我使用 jquery ajax 函数在一些输入字段和文本区域中添加内容。只有 textare 使用 TINYMCE。
但是在 ajax 之后,TINYMCE 中的文本不会刷新并保留。
如何使用 jquery 清空 TINYMCE 中的内容?
我当前的代码如下。
//on submit event
$("#specformentry").submit(function(event){
event.preventDefault();
if(checkForm()){
// var href = $(this).attr("href");
submitinput.attr({ disabled:true, value:"Sending..." });
//$("#send").blur();
//send the post to shoutbox.php
$.ajax({
type: "POST",
url: "../../Ajaxinsertspec",
data: $('#specformentry').serialize(),
complete: function(data){
update_entry();
specdesc.val('');
datecreated.val('');
detailstext.val('');
// this code is supposed to empty the INYMCE content, but it does not
//reactivate the send button
submitinput.attr({ disabled:false, value:"Enter Spec" });
}
});
}
else alert("Please fill all fields!");
//we prevent the refresh of the page after submitting the form
return false;
});
下面是HTML的一部分
<div id="enterlabel"><label for="spec_details">Click me to enter Spec Details</label></div>
<div style="display: block;" id="textarea">
<textarea style="display: none;" name="spec_details" cols="90" rows="12" id="detailstext"></textarea>
<span class="mceEditor defaultSkin" id="detailstext_parent">
<table style="width: 100px; height: 100px;" class="mceLayout" id="detailstext_tbl" cellpadding="0" cellspacing="0">
<tbody><tr class="mceFirst">
<td class="mceToolbar mceLeft mceFirst mceLast"><a href="#" accesskey="q" title="Jump to tool buttons - Alt+Q, Jump to editor - Alt-Z, Jump to...
...
最佳答案
清空 tinymce 不需要 jQuery。通过 id 获取 tinymce 实例并使用
将内容设置为''
(等于空)
//the id of the first editorinstance of the page is to be found in tinymce.editors[0].id
var tinymce_editor_id = 'my_tinymce_id';
tinymce.get(tinymce_editor_id).setContent('');
关于javascript - 如何在使用 jquery 执行 ajax 操作后清空 TINYMCE 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3874539/