我有一个“编辑模式”,其文本区域由API响应填充。它工作正常。 当我激活WYSIHTML5时,文本区域返回空。我尝试了其他富文本编辑器,但所有这些都不允许填充textarea。有什么办法可以使它正常工作?
在这里,我调用API:
$('.btnEditNews').live('click', function () {
var data = new FormData();
var xhr = new XMLHttpRequest();
var jsonResponse;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
jsonResponse = JSON.parse(this.response)['singleNews'];
$('#titleNews').val(jsonResponse.title);
$('#textNewsBody').html(jsonResponse.newsText);
$('#imgNews').attr('src', jsonResponse.file);
}
});
xhr.open("GET", url);
xhr.send(data);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
调用WYSIHTML5:
$('#textNewsBody').wysihtml5({
"font-styles": true, //Font styling, e.g. h1, h2, etc. Default true
"emphasis": true, //Italics, bold, etc. Default true
"lists": true, //(Un)ordered lists, e.g. Bullets, Numbers. Default true
"html": false, //Button which allows you to edit the generated HTML. Default false
"link": false, //Button to insert a link. Default true
"image": false, //Button to insert an image. Default true,
"color": false //Button to change color of font
});
<script src="lib/js/wysihtml5-0.3.0.js"></script>
提前谢谢!