选择器中包含大量/大量项目的 Jquery 在 IE8 上导致错误
我正在尝试运行一个具有大量要匹配的元素 id 的选择器,但在 IE8 中我不断收到错误:对象不支持此属性或方法。
jquery是这样的:
var elements = $('#182,#183,#184,#185,#211,#212,#213,#214,#220,#221,
#222,#223,#225,#226,#227,#228,#234,#241,#242,#243,#244,
#245,#246,#247,#248,#250,#251,#252,#253,#256,#257,#258,#259,#260');
实际的查询实际上更长并且id不是连续的。 我已将列表分解为更小的部分,并单独运行每个部分。 所有较小的选择器都运行良好。
我想知道是否有一种方法可以使用一个选择器?
这里的请求是标记的示例,但实际上有数百行:
<table id="ListTable">
<tbody>
<tr id="1" style="display: none;"></tr>
<tr id="2" style="display: none;"></tr>
<tr id="3" style="display: none;"></tr>
<tr id="4" style="display: none;"></tr>
<tr id="95" style="display: none;"></tr>
<tr id="5" style="display: none;"></tr>
<tr id="6" style="display: none;"></tr>
<tr id="7" style="display: none;"></tr>
<tr id="8" style="display: none;"></tr>
<tr id="9" style="display: none;"></tr>
<tr id="10" style="display: none;"></tr>
<tr id="11" style="display: none;"></tr>
<tr id="82" style="display: none;"></tr>
<tr id="83" style="display: none;"></tr>
<tr id="84" style="display: none;"></tr>
<tbody>
</table>
I am trying to run a selector that has a large number of element ids to match but in IE8 i keep getting the error: object doesnt support this property or method.
The jquery is like this:
var elements = $('#182,#183,#184,#185,#211,#212,#213,#214,#220,#221,
#222,#223,#225,#226,#227,#228,#234,#241,#242,#243,#244,
#245,#246,#247,#248,#250,#251,#252,#253,#256,#257,#258,#259,#260');
The actual query is actually longer and the ids are not sequential.
I have broken up the list into smaller parts and run each part separately.
All of the smaller selectors run fine.
I was wondering if there is a way i could use one selector?
As Requested here is an example of the markup but there is hundreds of rows in reality:
<table id="ListTable">
<tbody>
<tr id="1" style="display: none;"></tr>
<tr id="2" style="display: none;"></tr>
<tr id="3" style="display: none;"></tr>
<tr id="4" style="display: none;"></tr>
<tr id="95" style="display: none;"></tr>
<tr id="5" style="display: none;"></tr>
<tr id="6" style="display: none;"></tr>
<tr id="7" style="display: none;"></tr>
<tr id="8" style="display: none;"></tr>
<tr id="9" style="display: none;"></tr>
<tr id="10" style="display: none;"></tr>
<tr id="11" style="display: none;"></tr>
<tr id="82" style="display: none;"></tr>
<tr id="83" style="display: none;"></tr>
<tr id="84" style="display: none;"></tr>
<tbody>
</table>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在每个带有 ids 的元素上放置一个类(顺便说一句,不要仅使用带有数字的 ids。使它们更具描述性,只需使用子字符串解析它们)并调用该类,这样您将获得这些元素的数组:
假设你想选择:
然后你可以使用以下方法选择它们:
然后如果你想通过示例获取它们的ID,然后执行子字符串
*注意,你最好检查每个文件的文档,我实际上不确定这就是语法
put a class on each of those elements with ids(btw don't use ids with just numbers. make them a bit more descriptive and just parse them with substring) and call that class instead so you'll get an array of those elements:
say you wanted to select:
you can then select them all using:
then if you wanted to get their ids loop through example and then do a substring
*note, you better check the documentation for each, im not actually sure that's the syntax