我最终使用它,有太多的错误,我没有时间修复。 无论如何,这里是我做了什么,以获得保存的文本,以正确显示换行符(请检查是否如果你打算使用这个“黑客”的话,在将它保存到db之前源是好的)
$(document).ready(function() {
//Initialize JhtmlArea
$(".editor").htmlarea({
toolbar: [
["bold", "italic", "underline"],
["orderedList", "unorderedList"],
["link", "unlink"],
]
});
//Set id (id will be same for all instances)
$("iframe").attr("id", "editor");
// Style hack
$("#editor").contents().find('body').css({ "font-family": "MS Shell Dlg", "font-size": "12px", "font-weight": "100" });
// Finally to newlines hack
var html = $(".editor").htmlarea("toHtmlString");
// I would od something like $(".editor").htmlarea("html", "");
// But there is a bug since this function calls "pastHtml" internally
// which is a typo instead of
// "pasteHtml" so it won't work
$("#editor").contents().find('body').html("");
$(".editor").htmlarea("pasteHTML", html.replace(/\n/g, '<br\>'));
});