我找到了一些“解决方案”,但似乎没有一个对我有用。我正在使用 malsup 的 jquery 表单插件通过 POST 提交表单数据。表单元素之一是 nicEdit 框。这是我的代码:
html:
<div class="leftaligned">
<h1>Add News:</h1>
<form enctype="multipart/form-data" id="addnewsform" action="addnewscode.php" method="POST">
<input type="hidden" name="isnewnews" value=1 />
<div class="missinginfo">
Please add a title and some content!
</div>
<h2>Title:</h2>
<input type="text" size="50" id="newtitle" name="newtitle">
<h2>Content:</h2>
<textarea style="width:590px; height:300px;" id="newcontent" name="newcontent"></textarea>
<br>
<div id="contentbuttons">
<input type="submit" value="Add News" class="submitnews" style="float:left;" /></form>
<input type="button" value="Cancel" onclick='parent.$.colorbox.close(); return false;'/>
</div>
这是单击提交按钮时当前调用的内容:
<script>
$(document).ready(function() {
var options = {
beforeSubmit: function(arr, $form, options) {
var title = document.getElementById("newtitle").value;
var content = document.getElementById("newcontent").value;
alert(content);
var title = document.getElementById("newtitle").value;
if(title == "" || content == "") {
parent.$.fn.colorbox.resize({height:635});
$(".missinginfo").show();
setTimeout(function() {$(".missinginfo").hide();parent.$.fn.colorbox.resize({height:610});},2000);
return false;
}
},
success: showResponse
};
$('#addnewsform').submit(function() {
$(this).ajaxSubmit(options);
return false;
});
function showResponse(responseText, statusText, xhr, $form) {
parent.onAddNewsSuccess();
}
});
</script>
我的#newcontent 文本区域是一个 nicEdit 框。
警报(内容)没有显示任何内容,所以我知道我还需要做一些其他事情才能提交 nicEdit 框中的文本。我错过了什么?
最佳答案
(在问题编辑中回答。转换为社区 wiki 答案。请参阅 What is the appropriate action when the answer to a question is added to the question itself? )
OP 写道:
Nevermind, I solved it using:
beforeSerialize: function($form, options) { nicEditors.findEditor('newcontent').saveContent(); },
关于jquery - 通过 ajax POST 提交 nicEdit 文本编辑器的值不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11641255/