百度编辑器不能插入html标签解决方法

在ueditor.all.js文件中找到此方法:

  1.  
    me.addInputRule(function (root) {
  2.  
    var allowDivTransToP = this.options.allowDivTransToP;
  3.  
    var val;
  4.  
    function tdParent(node){
  5.  
    while(node && node.type == 'element'){
  6.  
    if(node.tagName == 'td'){
  7.  
    return true;
  8.  
    }
  9.  
    node = node.parentNode;
  10.  
    }
  11.  
    return false;
  12.  
    }
  13.  
     
  14.  
    // case 'style':
  15.  
    // case 'script':
  16.  
    // node.setAttr({
  17.  
    // cdata_tag: node.tagName,
  18.  
    // cdata_data: (node.innerHTML() || ''),
  19.  
    // '_ue_custom_node_':'true'
  20.  
    // });
  21.  
    // node.tagName = 'div';
  22.  
    // node.innerHTML('');
  23.  
    // break;
  24.  
     
  25.  
    // var cssStyle = node.getAttr('style');
  26.  
    // if (cssStyle) {
  27.  
    // cssStyle = cssStyle.replace(/(margin|padding)[^;]+/g, '');
  28.  
    // node.setAttr('style', cssStyle)
  29.  
    //
  30.  
    // }
  31.  
    //p标签不允许嵌套
  32.  
    // utils.each(node.children,function(n){
  33.  
    // if(n.type == 'element' && n.tagName == 'p'){
  34.  
    // var next = n.nextSibling();
  35.  
    // node.parentNode.insertAfter(n,node);
  36.  
    // var last = n;
  37.  
    // while(next){
  38.  
    // var tmp = next.nextSibling();
  39.  
    // node.parentNode.insertAfter(next,last);
  40.  
    // last = next;
  41.  
    // next = tmp;
  42.  
    // }
  43.  
    // return false;
  44.  
    // }
  45.  
    // });
  46.  
    })

 将这些对标签处理的逻辑都注释掉,当然后面还有别的标签,大家自己根据自己的需求看是否需要注释。

还有一点需要说明,div标签会自动变成p标签,这里的设置可以在ueditor.config.js文件中找到配置项

搜索allowDivTransToP配置项,将此项改为false,就不会把div改成p了。

原文地址:https://www.cnblogs.com/surplus/p/14772709.html