在項(xiàng)目中青柄,一個(gè)文章修改模塊用到ueditor,
但是每次修改完文章點(diǎn)擊保存后预侯,ueditor就會(huì)自動(dòng)套上一個(gè)p標(biāo)簽致开,
多次修改后,ueditor就會(huì)不斷的在外層套一個(gè)p標(biāo)簽萎馅,以至于明明沒(méi)有修改双戳,但是它卻不斷的換行。
方法一:(嘗試失斆臃肌)
不允許修改ueditor默認(rèn)源碼的配置飒货,只能選擇覆蓋掉魄衅。
<!--覆蓋ueditor自動(dòng)生成的p標(biāo)簽-->
var?editor?=?UE.getEditor('editor',{?????
enterTag?:'br'??
});??
方法二:(找到文本模塊中DajngoUEditor文件中的ueditor.all.js,嘗試失斕粮ā)
將自動(dòng)生成p標(biāo)簽的內(nèi)容全部注釋掉
//進(jìn)入編輯器的li要套p標(biāo)簽
? ? me.addInputRule(function(root){
//? ? ? ? utils.each(root.getNodesByTagName('li'),function(li){
//? ? ? ? ? ? var tmpP = UE.uNode.createElement('p');
//? ? ? ? ? ? for(var i= 0,ci;ci=li.children[i];){
//? ? ? ? ? ? ? ? if(ci.type == 'text' || dtd.p[ci.tagName]){
//? ? ? ? ? ? ? ? ? ? tmpP.appendChild(ci);
//? ? ? ? ? ? ? ? }else{
//? ? ? ? ? ? ? ? ? ? if(tmpP.firstChild()){
//? ? ? ? ? ? ? ? ? ? ? ? li.insertBefore(tmpP,ci);
//? ? ? ? ? ? ? ? ? ? ? ? tmpP = UE.uNode.createElement('p');
//? ? ? ? ? ? ? ? ? ? ? ? i = i + 2;
//? ? ? ? ? ? ? ? ? ? }else{
//? ? ? ? ? ? ? ? ? ? ? ? i++;
//? ? ? ? ? ? ? ? ? ? }
//
//? ? ? ? ? ? ? ? }
//? ? ? ? ? ? }
//? ? ? ? ? ? if(tmpP.firstChild() && !tmpP.parentNode || !li.firstChild()){
//? ? ? ? ? ? ? ? li.appendChild(tmpP);
//? ? ? ? ? ? }
//trace:3357
//p不能為空
//? ? ? ? ? ? if (!tmpP.firstChild()) {
//? ? ? ? ? ? ? ? tmpP.innerHTML(browser.ie ? ' ' : '
')
//? ? ? ? ? ? }
//去掉末尾的空白
//? ? ? ? ? ? var p = li.firstChild();
//? ? ? ? ? ? var lastChild = p.lastChild();
//? ? ? ? ? ? if(lastChild && lastChild.type == 'text' && /^\s*$/.test(lastChild.data)){
//? ? ? ? ? ? ? ? p.removeChild(lastChild)
//? ? ? ? ? ? }
//? ? ? ? });
方法三:??加“|safe”
感謝原出處
http://www.reibang.com/p/5584c65b675b
之前:
<div class="jieshao">
? ? <span class="jieshao_banner">商品介紹</span>
? ? <div class="goods_detailcontent">{{goods.gdetailcontent}}</div>
</div>
上圖的文字自動(dòng)追加了<p>標(biāo)簽解決方法是在前端引用時(shí)加入|safe:
之后: