いくつかの問題点: getElementsByTagNameは、配列ではなくノードコレクションを作成します。 利用可能なメソッドとプロパティに関する限り、Nodeコレクションは非常に限定されています。
ここでは、ノードコレクションについて知っておくべき重要な事項を簡潔に説明します。
コレクションはgetElementsByTagNameのを実行した後、アレイ
http://www.sitepoint.com/a-collection-is-not-an-array/
はありませんが、私は、配列にコレクションを移動しました。 要素は使用可能な形式ではないため、それらをDOM要素にも変換しました。
要素選択で作業するのではなく、要素Nodeから作成した範囲選択を使用しました。私は範囲がより柔軟に働くことがわかった。
http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.dom.range.html
最後に、選択した要素を含むDOM選択オブジェクトを作成しました。選択オブジェクトで使用できるさまざまなメソッドを使用して、いくつかのサンプルオブジェクトを作成しました。
http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.dom.selection.html
オブジェクトタイプ[オブジェクトオブジェクト]と[オブジェクトHTMLDocument]についてのメモを確認しました。 FireBugで "console.log();"を使ってみましたか?各オブジェクトのすべての利用可能なメソッドとプロパティが表示されます。私は含まれているコードのオブジェクトのほとんどのためにそれを追加しました。あなたの考えを見てください。
FireBugのコンソールパネルで、ログが実行されている各オブジェクトの情報を確認してください。 console.log(CKEDITOR)を試してください。利用可能なものの概要を知ることができます。
重要注意:Internet Explorerの場合、「console.log();」を使用している間は、「開発者ツール」ウィンドウを開き、スクリプトパネルで「デバッグ」をアクティブにする必要があります。それ以外の場合は、エラーが発生します。ここで
はコードです:
var selectOption = dialog.getValueOf('find', 'findNext');
var documentWrapper = editor.document; // [object Object] ... CKEditor object
var documentNode = documentWrapper.$; // [object HTMLDocument] .... DOM object
// NEW - This isn't an array. getElementsByTagName creates a Node collection
// Changed name from elementArray to elementCollection
elementCollection = documentNode.getElementsByTagName(selectOption);
// NEW - Can't use array methods on Node Collection, so move into array and
// change the collection items into DOM elements
// NEW - Caveat: The collection is live,
// so if changes are made to the DOM it could modify the var elementCollection
var nodeArray = [];
for (var i = 0; i < elementCollection.length; ++i) {
nodeArray[i] = new CKEDITOR.dom.element(elementCollection[ i ]);
}
// NEW - Working with an element object is problematic.
// Create a range object to use instead of an element
// http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.dom.range.html
var rangeObjForSelection = new CKEDITOR.dom.range(editor.document);
console.log(rangeObjForSelection);
// NEW - Populate the range object with the desired element
rangeObjForSelection.selectNodeContents(nodeArray[ count ]);
console.log(rangeObjForSelection);
// OLD - editor.getSelection().selectElement(elementCollection[count]);
// Trying to make the current element of type selectElement
// NEW - Highlight the desired element by selecting it as a range
editor.getSelection().selectRanges([ rangeObjForSelection ]);
// OLD - var elementX = editor.getSelection().getSelectedElement();
// NEW - Create a DOM selection object.
var selectedRangeObj = new CKEDITOR.dom.selection(editor.document);
console.log(selectedRangeObj);
// NEW - You can look at the properties and methods available
// http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.dom.selection.html
// I've created sample objects using the methods that seem most useful.
var elementX = selectedRangeObj.getRanges();
console.log(elementX);
var elementX2 = selectedRangeObj.getStartElement();
console.log(elementX2);
var elementX3 = selectedRangeObj.getSelectedText();
console.log(elementX3);
var elementX4 = selectedRangeObj.getNative();
console.log(elementX4);
は、まあ ジョー
て、私はあなたが間違ったCKEditorバージョンメソッドを使用していると思います。あなたの目標は何ですか?要素を選択するには?または、idで単一の要素を選択しますか? – Ken
いいえ、selectElement()メソッドは、getSelectedElement()メソッドがこのハイライト表示された要素を返すように要素を強調表示すると考えています。 – oggiemc