UEditor 粘贴 Excell 中的表格时报错导致无法粘贴的解决办法

    在UEditor一些版本中,如果粘贴Excell中的内容到编辑器,会粘贴不进去,打开控制台发现JS报错了。

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

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

    看这个错误应该就能知道导致错误的原因可能是调用 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 = '';
                    //if(node.getAttributeNode('style') != null){ //加上这句
            //3048            !browser.ie && node.removeAttributeNode(node.getAttributeNode('style'))
                    //}
            }
            node.removeAttribute(ci);
        }
    },

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



  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值