我正在尝试使用 Imperavi Redactor在这里控制我的富文本编辑:
<div class="control-group">
<%= f.label :description %>
<div class="controls">
<%= f.text_area :description, :class => "richtext" %>
</div>
</div>
$(document).ready(function(){
$('.richtext').redactor();
});
富文本编辑器显示并且工作正常,但是当我输入内容时,我可以使用 Google Chrome 中的检查元素看到 html 标记没有被复制到隐藏文本区域。请参阅:
<div class="controls">
//Removed toolbar for brevity.
<div class="redactor_box">
<div class="redactor_richtext redactor_editor" contenteditable="true" dir="ltr"><p>asdfjoiasjdf</p><p>dfjiasdfjiasd</p><p>idsfj</p><p>asdffaas</p></div>
</div>
<textarea class="richtext" cols="40" id="program_description" name="program[description]" rows="20" style="display: none;"></textarea></div>
</div>
当对该文本区域执行表单 POST 时,服务器显然看不到任何内容,因为文本区域是空白的。
关于如何将丰富的 html 复制到文本区域有什么建议吗?我做错了什么?
最佳答案
尝试内置函数$().syncCode()
syncCode: function()
{
var html = this.formatting(this.$editor.html());
this.$el.val(html);
}
或$().setCode()
setCode: function(html)
{
html = this.preformater(html);
this.$editor.html(html).focus();
this.syncCode();
},
关于javascript - Imperavi Redactor 内容未复制到隐藏文本区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14636003/