我最終使用它,有太多的錯誤,我沒有時間修復。 無論如何,這裏是我做了什麼,以獲得保存的文本,以正確顯示換行符(請檢查是否如果你打算使用這個「黑客」的話,在將它保存到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\>'));
});