KindEditor得不到textarea值的解决方法
<script language = "JavaScript"> KindEditor.ready(function(K) { var editor1 = K.create('textarea[name="Content"]', { cssPath : 'kindeditor-4.1.10/plugins/code/prettify.css', uploadJson : 'kindeditor-4.1.10/asp/upload_json.asp', fileManagerJson : 'kindeditor-4.1.10/asp/file_manager_json.asp', allowFileManager : true, afterCreate : function() { var self = this; K.ctrl(document, 13, function() { self.sync(); K('form[name=myform]')[0].submit(); }); K.ctrl(self.edit.doc, 13, function() { self.sync(); K('form[name=myform]')[0].submit(); }); }, afterBlur: function(){this.sync();} }); prettyPrint(); }); </script>
从44行测试到86行, 从来没有这么艰辛过。 万千翻遍各种资料查阅,结果原来是这。
相关说明:
从上面的代码可以看到,解决方法在于最后一行代码,afterBlur: function(){this.sync();},当失去焦点时执行 this.sync();
那么这个 this.sync(); 函数是干嘛的呢?简单的说:这个函数就是同步KindEditor的值到textarea文本框。
本人开发APP的实例:
<script>
KindEditor.ready(function(K) {
var editor1 = K.create('textarea[name="infocontent"]', {
cssPath : 'Kindeditor/plugins/code/prettify.css',
uploadJson : 'Kindeditor/asp/upload_json.asp',
fileManagerJson : 'Kindeditor/asp/file_manager_json.asp',
allowFileManager : true,
items: ['source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste', 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript', 'superscript', 'clearhtml', 'quickformat', 'selectall', '/', 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak', 'anchor', 'link','image', 'unlink', 'fullscreen'],
afterCreate : function() {
var self = this;
K.ctrl(document, 13, function() {
self.sync();
K('form[name=AddPro]')[0].submit();
});
K.ctrl(self.edit.doc, 13, function() {
self.sync();
K('form[name=AddPro]')[0].submit();
});
}
/*****
真想X你,就这个代码浪费了一天时间,结果 afterCreate 换成 afterBlur 即可 或者加一个afterBlur:function(){this.sync();} 即可
相关说明:从上面的代码可以看到,解决方法在于最后一行代码,afterBlur: function(){this.sync();},
当失去焦点时执行 this.sync();
那么这个 this.sync(); 函数是干嘛的呢?简单的说:这个函数就是同步KindEditor的值到textarea文本框。
*****/
afterBlur:function(){this.sync();}
});
prettyPrint();
});
</script>