百度UEditor富文本编辑器 如何去除自动默认添加的p标签

2018-12-0717:38:25网站建设与开发Comments11,733 views字数 1158阅读模式

UEditor是百度研发的一个很好的文本编辑器,但是在使用过程中,默认的是每次都会自动追加p标签。但是在很多情况下,我并不需要这p标签,为此很闹心。那有没有什么办法消除这自动添加的p标签呢?文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/8550.html

方法如下:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/8550.html

首先:打开ueditor.all.js(或ueditor.all.min.js)。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/8550.html

1、搜索修改成false:allowDivTransToP: false文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/8550.html

2、再搜索并修改以下:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/8550.html

//编辑器不能为空内容
if (domUtils.isEmptyNode(me.body)) {
me.body.innerHTML = '';
}

3、搜索“/给文本或者inline节点套p标签”,并且替换以下内容文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/8550.html

//给文本或者inline节点套p标签
if (me.options.enterTag == 'p') {
  var child = this.body.firstChild, tmpNode;
  if (!child || child.nodeType == 1 &&
    (dtd.$cdata[child.tagName] || isCdataDiv(child) ||
      domUtils.isCustomeNode(child)
      )
    && child === this.body.lastChild) {
    this.body.innerHTML = '' + this.body.innerHTML;
  } else {
    var p = me.document.createElement('div');
    while (child) {
      while (child && (child.nodeType == 3 || child.nodeType == 1 && dtd.p[child.tagName] && !dtd.$cdata[child.tagName])) {
        tmpNode = child.nextSibling;
        p.appendChild(child);
        child = tmpNode;
      }
      if (p.firstChild) {
        if (!child) {
          me.body.appendChild(p);
          break;
        } else {
          child.parentNode.insertBefore(p, child);
          p = me.document.createElement('div');
        }
      }
      child = child.nextSibling;
    }
  }
}

4、搜索 “进入编辑器的li要套p标签”,这块也要注释掉文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/8550.html

5、注视掉这段:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/8550.html

node.className = utils.trim(node.className.replace(/list-paddingleft-\w+/,'')) + ' list-paddingleft-' + type;

6、最后注视掉:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/8550.html

li.style.cssText && (li.style.cssText = '');

完美解决,以上是整个流程,不过有些浏览需要清空缓存才能起作用。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/8550.html

  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/cms/8550.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定