我正在使用jQuery和TinyMCE提交表单,但是序列化中有一个问题,因为Textarea值不能post。
代码如下:
<form id="myForm" method="post" action="post.php">
<textarea name="question_text" id="question_text" style="width:543px;height:250px;"></textarea>
</form>
语言: lang-js
$('#myForm').submit(function() {
$.ajax({
type: 'POST',
url: $(this).attr('action'),
data: $(this).serialize(),
success: function(data) {
$('#result').fadeIn('slow');
$('#result').html(data);
$('.loading').hide();
}
})
return false;
});
tinyMCE.init({
// General options
mode : "textareas",
theme : "advanced",
// Theme options
theme_advanced_buttons1 : "bold,italic,underline,separator,image,separator,justifyleft,justifycenter,justifyright,jformatselect,fontselect,fontsizeselect,justifyfull,bullist,numlist,undo,redo,styleprops,cite,link,unlink,media,advhr,code,preview",
theme_advanced_buttons2 : "",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resize_horizontal : false,
theme_advanced_resizing : true,
extended_valid_elements :"a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
});
你能给我解释一下我应该做什么修改吗?为什么要修改,以便在文本区域中张贴数值?
发布于 2010-02-15 23:29:54
在提交表单之前,请调用tinyMCE.triggerSave();
发布于 2014-06-18 19:55:19
您可以按如下方式配置TinyMCE,以便在通过TinyMCE编辑器进行更改时保持隐藏文本rea值的同步:
tinymce.init({
selector: "textarea",
setup: function (editor) {
editor.on('change', function () {
editor.save();
});
}
});
textarea元素将自动保持最新,在序列化表单等之前不需要任何额外的步骤。
这已经在TinyMCE 4.0上进行了测试
演示运行于:http://jsfiddle.net/9euk9/49/
更新:上面的代码已经根据DOOManiac的评论进行了更新
发布于 2010-01-23 12:40:11
这是因为它不再是一个文本区。它被替换为iframe (等等),并且serialize函数只从表单域获取数据。
将隐藏字段添加到表单:
<input type="hidden" id="question_html" name="question_html" />
在发布表单之前,从编辑器获取数据并将其放入隐藏字段:
$('#question_html').val(tinyMCE.get('question_text').getContent());
(如果您正常发布表单,编辑器当然会自己处理这件事,但由于您在不使用表单的情况下自己抓取表单并发送数据,所以表单上的onsubmit事件永远不会被触发。)
https://stackoverflow.com/questions/2122085
复制相似问题