[英]How to get value of a textarea which is controlled by a javascript html editor?
I am trying to write a code which allows my website users to save drafts. 我正在尝试编写一个代码,允许我的网站用户保存草稿。 I am facing a problem while doing this.
这样做时我遇到了问题。
HTML HTML
<input type="button" value="SAVE DRAFT" onClick="saveit()">
<textarea id="content" name="content" class="widgEditor nothing">initial text</textarea>
JavaScript JavaScript的
function saveit() {
var content = $('#content').val();
alert (content);
//some other ajax codes to save draft...
}
When I click the Save draft
button, it always shows initial text
even if I change the text in the textarea (editor). 当我单击“
Save draft
按钮时,即使我更改了textarea(编辑器)中的文本,它也始终显示initial text
。
I have tired this with widgEditor and CKeditor but unfortunately I could not figure out how to fix this problem. 我已经厌倦了widgEditor和CKeditor,但不幸的是我无法弄清楚如何解决这个问题。
NOTE: When I try this without any WYSIWYG editor, it works properly but that text area needs to be an editor. 注意:当我在没有任何WYSIWYG编辑器的情况下尝试此操作时,它可以正常工作但文本区域需要是编辑器。
Can anyone help me with this? 谁能帮我这个?
This could probably help if you use CKEditor: 如果您使用CKEditor,这可能会有所帮助:
Using jQuery to grab the content from CKEditor's iframe 使用jQuery从CKEditor的iframe中获取内容
Essentially, you use this before you read the value: 基本上,在读取值之前使用它:
for ( instance in CKEDITOR.instances )
CKEDITOR.instances[instance].updateElement();
Also I think you should use .text(), not .val() when working with textareas. 另外我认为你在使用textareas时应该使用.text(),而不是.val()。
Don't use onClick
不要使用
onClick
$(':button').click(function() {
var content = $("#content").val();
alert( content );
//some other ajax codes to save draft...
});
works fine 工作正常
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.