我在一个页面中动态生成了许多 ckeditor 实例,并且在 ckeditor 的 instanceReady 函数中,我获取了每个 ckeditor 的实例,并从那里获得了我分配 id 的 iFrame 引用。现在,当我说 iFrameDocument.getElementById(assignedIframeId) 时分配了一个 id 后,我无法找到 iFrame。这是我的代码:
<html>
<body>
<!-- This is the template. The div tag with class="contents" will be replaced with CKEditor -->
<script type="text/html" id="PS_ItemViewModel-template">
<div id="mgrComments" class="document comment-region">
<div class="contents" data-bind="html : mgrComments"></div>
</div>
</script>
<!-- looping the template based on the number of items -->
<div class="ps-item-container" data-bind="foreach : psItems">
<div data-bind="template : {'name' : 'PS_ItemViewModel-template'}, event
: {psItemSetupEditor : _setupEditor, psItemRefreshEditor : _refreshEditor}"></div>
</div>
</body>
</html>
// In the javascript file ...
self._setupEditor = function(data, event){
var domNode = event.currentTarget;
self.editor = self._injectEditorInstance($(domNode).find('div#mgrComments div.contents'), self.mgrComments, self.headerNode, self.criterionNodes);
}
self._injectEditorInstance = function(commentNode, initialText, headerNode, criterionNodes) {
$('div#editor-toolbar').show();
commentNode.ckeditor(function(){
console.log("Inside commentNode.ckeditor ...");
var editor = this;
this.setData(initialText, function(){
//Handles direct changes to editor contents
editor.on('setData', function() {
self.editorChangeHandler(editor);
});
//Handles paste
editor.on('paste', function() {
console.log("In paste event ...");
self.editorChangeHandler(editor);
});
});
}, {customConfig : '/simple_eval/js/ckeditor/SimpleEvalEditorConfig.js'});
return commentNode.ckeditorGet();
};
$(document).ready(function() {
CKEDITOR.on("instanceReady", function(e) {
console.log("In instanceReady ...................................");
var assignedId = e.editor.name + "jspell";
$("#cke_contents_" + e.editor.name+" iframe").attr("id", assignedId);
var iframeDoc = null;
$('#'+assignedId).each(
function(){ iframeDoc=this.contentWindow.document;}
);
console.log(" innerDoc Element = "+iframeDoc.getElementById(assignedId));
fieldsToCheck[fieldsToCheck.length] = [iframeDoc, assignedId];
jspellInit();
});
});
var fieldsToCheck = new Array();
function getSpellCheckArray() {
console.log("In getSpellCheckArray ...................................");
return fieldsToCheck;
}
在上面的代码中,当我说 console.log(" innerDoc Element = "+iframeDoc.getElementById(assignedId)); 它打印出 null,这意味着在 iframe 文档中找不到该元素。有人可以建议我如何将 id 分配给 ckeditor 的 iframe,以便可以使用 iframe 分配的 id 来检索它。
谢谢。