UEditor 粘贴表格时报错致使没法粘贴的解决方法

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

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

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

或者ide

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

看这个错误应该就能知道致使错误的缘由多是调用 removeAttributeNode的对象为null或者传进 removeAttributeNode 中的参数为null。code

定位到这行代码看一下:对象

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 的判断,如上代码所示。blog

相关文章
相关标签/搜索