• UEditor 粘贴表格时报错导致无法粘贴的解决方法


    在UEditor一些版本中,比如我的版本为1.3.6或者说是1.4以前的版本,如果粘贴Excell中的内容或者粘贴表格之类的到编辑器,会粘贴不进去,打开控制台发现JS报错了。

    在ueditor.all.js:3048行报如下错误:

    Uncaught TypeMismatchError: Failed to execute 'removeAttributeNode' on 'Element': The node provided is invalid.

    或者

    Uncaught TypeError: Failed to execute 'removeAttributeNode' on 'Element': parameter 1 is not of type 'Attr'.

    看这个错误应该就能知道导致错误的原因可能是调用 removeAttributeNode的对象为null或者传进 removeAttributeNode 中的参数为null。

    定位到这行代码看一下:

    removeAttributes:function (node, attrNames) {
            attrNames = utils.isArray(attrNames) ? attrNames : utils.trim(attrNames).replace(/[ ]{2,}/g,' ').split(' ');
            for (var i = 0, ci; ci = attrNames[i++];) {
                ci = attrFix[ci] || ci;
                switch (ci) {
                    case 'className':
                        node[ci] = '';
                        break;
                    case 'style':
                        node.style.cssText = '';
                        //!browser.ie && node.removeAttributeNode(node.getAttributeNode('style'))
                        if (node.getAttributeNode('style') != null) {
                            !browser.ie && node.removeAttributeNode(node.getAttributeNode('style'))
                        }
                }
                node.removeAttribute(ci);
            }
        },

    导致错误的原因就是3048行 node.getAttributeNode('style') 返回null,然后传入了 removeAttributeNode 里。解决的方法是加入node.getAttributeNode('style') 为 null 的判断,如上代码所示。

  • 相关阅读:
    日记 2018/1/12
    【程序员笔试面试必会——排序①】Python实现 冒泡排序、选择排序、插入排序、归并排序、快速排序、堆排序、希尔排序
    Python笔试、面试 【必看】
    高性能Go并发
    Go连接MySql数据库Error 1040: Too many connections错误解决
    MAC 配置文件 ~/.zshrc
    go-statsd项目
    日记 2017.11.20
    sed 命令详解
    Opentsdb简介(一)
  • 原文地址:https://www.cnblogs.com/w-zoe/p/6283530.html
Copyright © 2020-2023  润新知