在Chrome上执行多个选择器时,jQuery中的INVALID_NODE_TYPE_ERR [英] INVALID_NODE_TYPE_ERR in jQuery when doing multiple selectors on Chrome

查看:203
本文介绍了在Chrome上执行多个选择器时,jQuery中的INVALID_NODE_TYPE_ERR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  element.find(fieldset,input [type = hidden] ,输入[type = text],:radio])

并且在Chrome版本1中出现此错误第722行的jquery选择器的INVALID_NODE_TYPE_ERR:DOM Range Exception 2 .js

  aRange.selectNode(a); 

在上下文中:

 函数(a,b){
var aRange = a.ownerDocument.createRange(),bRange = b.ownerDocument.createRange();
Range.selectNode(a);
Range.collapse(true);
bRange.selectNode(b);
bRange.collapse(true);
var ret = aRange.compareBoundaryPoints(Range.START_TO_END,bRange);
if(ret === 0){
hasDuplicate = true;
}
return ret;
}

在这种情况下, a 是HTML隐藏输入字段。从我发现的情况来看,它似乎是旧版webkit的一个问题,因为这个错误在Chrome的新测试版中不会发生(可能是因为它从来没有打过这个代码,因为它实现了 document.documentElement.compareDocumentPosition 参见 selector.js#703 )。

为了解决这个问题,我用四个单选项替换了多选择器,合并在一起工作正常,但它真的很难看:

$ p $元素元素.find('fieldset')
。添加(element.find( '输入[类型=隐藏]'));
.add(element.find('input [type = text]'));
.add(element.find(':radio'));

这真的是解决这个问题的唯一方法吗?还是有其他方法可以做?



更新 关于这个在Sizzle讨论论坛上的帖子,Sizzle(jQuery选择器)代码的一个可能的补丁已经发布,这可能会发现它进入jQuery核心的方式。这似乎只是一个问题,当在动态代码上进行多重选择时,如果问题出在Web浏览器上,那么可悲的是,没有什么可以做的,只是等待更新,或者使用多个选择器并合并结果集。从它看起来,这不会是一个很大的性能打击,因此我不会担心它。


I'm doing a jQuery multiple selector find:

element.find("fieldset, input[type=hidden], input[type=text], :radio")

and in Chrome version 1 it gives this error "INVALID_NODE_TYPE_ERR: DOM Range Exception 2" on line 722 of jquery's selector.js

aRange.selectNode(a);

in context:

function(a, b) {
    var aRange = a.ownerDocument.createRange(), bRange = b.ownerDocument.createRange();
    aRange.selectNode(a);
    aRange.collapse(true);
    bRange.selectNode(b);
    bRange.collapse(true);
    var ret = aRange.compareBoundaryPoints(Range.START_TO_END, bRange);
    if (ret === 0) {
        hasDuplicate = true;
    }
    return ret;
}

in this case, a is a HTML hidden input field. From what I can find, it seems to be an issue with the older webkit version, as this error doesn't occur in the new beta of Chrome (probably because it never hits this code because it implements document.documentElement.compareDocumentPosition see selector.js#703).

To step around this problem, I've replaced the multi-selector with four single selects which I merge together which works fine, but it's really ugly:

elements = element.find('fieldset')
.add(element.find('input[type=hidden]'));
.add(element.find('input[type=text]'));
.add(element.find(':radio'));

Is this really the only way around this, or is there something else I can do?

UPDATE There is a thread about this on the Sizzle discussion forum, a possible patch to the Sizzle (jQuery selector) code has been posted, this may find its way into jquery core. It seems to only be an issue when doing a multiple selector on dynamic code

解决方案

if the problem is the web browser, then sadly there is nothing you can do but wait for an update, or use the multiple selectors and merge the result sets. From what it looks like, this wouldn't be a big performance hit at all, and thus I wouldn't worry about it.

这篇关于在Chrome上执行多个选择器时,jQuery中的INVALID_NODE_TYPE_ERR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆