关于帖子/文章重新编辑后正文出现错乱问题解决方案

分享 未结 0 1691
社区小编
社区小编 管理员 2020年6月25日 08:34 发表

近期发现帖子或文章经过重新编辑发布后,正文直接错乱或异常,现记录解决方案过程,以便使用此版本朋友借鉴修改:


1、找到\resources\templates\p\add.html 文件

定位到如下位置

<div>
<div id="editor">
<p id="descriptionP" th:text="${description}"></p>
</div>
<textarea name="description" id="description"

cols="30"
rows="10"
style="display:none;"
></textarea>
</div>

修改为:

<div>
<div id="editor" th:data="${description}">
</div>
<textarea name="description" id="description"

cols="30"
rows="10"
style="display:none;"
></textarea>
</div>


2、找到:main\resources\static\js\myeditor.js文件

定位到:

var $description = $('#description')
editor.customConfig.onchange = function (html) {
// 监控变化,同步更新到 textarea
$description.val(html)
}
editor.create();
// 初始化 textarea 的值
$description.val(editor.txt.html());
//var objeditor = document.getElementById("editor");
var obj = document.getElementById("descriptionP");
//alert(obj.innerText);//这样就自动解析了
obj.innerHTML = obj.innerText;//这样重新设置html代码为解析后的格式

修改为:

var $text1 = $('#description');

if ($('#editor').attr("data") != undefined){
$('#editor').html($('#editor').attr("data"));
}

editor.customConfig.onchange = function (html) {
// 监控变化,同步更新到 textarea
$text1.val(html)
}

editor.create();

// 初始化 textarea 的值
$text1.val(editor.txt.html());



收藏(2)  分享
相关标签: 笔记
问题没解决?让chatGPT帮你作答 智能助手
0个回复
  • 消灭零回复