問: 在通過Jquery來獲得使用kindeditor編輯器時(shí)的內(nèi)容時(shí), 始終獲得得內(nèi)容是空值, 而通過form表單提交時(shí), 又可以獲得編輯的內(nèi)容, 這是什么原因呢?
答: 因?yàn)樵谑褂胘s/jquery來獲得內(nèi)容時(shí), 沒有同步數(shù)據(jù)到textarea, 使用editor.sync('editor_id')可解決問題;
具體方法如下:
HTML代碼:
<textarea name="intro" id="editor_id" style="width:700px; height:450px;"></textarea> <input type="button" value="提交" />
Jquery代碼如下:
KindEditor.ready(function(K) { window.editor = K.create('#editor_id'); }); $(function(){ $("input[type='button']").click(function(){ editor.sync('editor_id');//同步數(shù)據(jù)后可以直接取得textarea的value var content = $("#editor_id").val(); if(content=="")alert("內(nèi)容不能為空"); }); })