我想在网络基础上创建聊天。我使用CKEDITOR作为B,I,U,字体类型,字体大小就像Yahoo Messenger或其他IM
我成功抓住了输入密钥。但是当我调用my_ckeditor_inctance_obj.setData('')时,我收到了这个错误; 我之所以这样称呼是因为按下输入文字就会像其他聊天程序(FB,YM等)一样消失
我用过铬。 Chrome的控制台说
Uncaught TypeError: Cannot call method 'equals' of null ckeditor.js:36
// Detail Error
d.range.getCommonAncestor ckeditor.js:36
(anonymous function) ckeditor.js:133
s ckeditor.js:54
j.enterkey.enterBlock ckeditor.js:53
(anonymous function)
但是,我也使用了按钮发送。当我点击发送。它完美无缺。
这是我的源代码:
$(document).ready(function(){
// Init CKEDITOR
CKEDITOR.replace('editor1',{
toolbar:[['Bold','Italic','Underline'],['Font','FontSize'],['TextColor','BGColor']]
});
// Handle for keypress. In this case is When ENTER key is press
CKEDITOR.instances['editor1'].on('contentDom', function() {
this.document.on('keydown', function(e){
if(e.data.getKey() == 13){ // Do this code when ENTER is pressed
var temp=getContent();
console.log(temp);
}
});
});
});
function getContent(){
// Get the editor instance that you want to interact with.
var oEditor = CKEDITOR.instances.editor1;
// Get editor contents
// http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#getData
var temp=oEditor.getData();
//set to blank again
oEditor.setData(''); // This code make error --> Uncaught TypeError: Cannot call method 'equals' of null ckeditor.js:36 BUT when click 'send' button this error didn't show.(send button use this function)
return temp;
}
如何解决这个问题?
THX 健次郎
更新: 我在这里找到了解决方案enter key for save textarea values 特别要求AlfonsoML