数组成员可以充当多个 jQuery 选择器以及单独匹配的对象吗?
这是一种常见情况,但经过 Google + SO 搜索后,我一直无法找到简单的解决方案。虽然 与这个问题类似,重点不是聚集一个多维数组,而是简单地采取行动无论哪个选择器“获胜”,而不是选择器的整个“总和”。示例:
var findThese = ['name', 'telephone', 'brasize'];
var chiXML = "<philly><name>sandy</name><brasize>49DDD</brasize></philly>"
+ "<philly><name>amber</name><telephone>976</telephone></philly>";
$(findThese).find(chiXML)
.parent()
.data(the_1of3_matched_selector_from_findThese, theMatched Text);
最终的结果模糊地类似于...
<philly data-name="sandy" data-brasize="49DDD">
<name>sandy</name><brasize>49DDD</brasize></philly>
</philly>....
抱歉,如果我的示例很糟糕...但是我要表达的意思... 是否可以“音译”列表/数组 - 作为“多项选择” jQuery 选择器 - 然后可以在查询操作的回调/函数部分期间单独使用 OR 进行操作?
It's a common circumstance, but after a through Google + SO search, I have been unable to find a simple solution.. Although similar to this question, the point is not to amass a multi-dimensional array, but simply to ACT on whichever selector "Won", not on the entire "sum" of selectors. Example:
var findThese = ['name', 'telephone', 'brasize'];
var chiXML = "<philly><name>sandy</name><brasize>49DDD</brasize></philly>"
+ "<philly><name>amber</name><telephone>976</telephone></philly>";
$(findThese).find(chiXML)
.parent()
.data(the_1of3_matched_selector_from_findThese, theMatched Text);
ending up with something vaguely like...
<philly data-name="sandy" data-brasize="49DDD">
<name>sandy</name><brasize>49DDD</brasize></philly>
</philly>....
Sorry if my example sucks... but what I'm getting at... is it possible to "transliterate" a list / array - as a "multiple choice" jQuery selector - which can then be acted with OR upon INDIVIDUALLY, during the callback / function portion of the query operation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你想要这样的东西:
如果我理解正确的话,你需要知道你的结果匹配多重选择器的哪一部分并根据该值采取行动。
您可以像我上面所做的那样分解选择器,并独立地对每个部分进行操作,使您更容易知道选择器的哪一部分得到满足。
I think you want something like this:
If I understand you correctly, you need to know what part of a multiple selector your results match and act on that value.
You can break up the selector as I've done above and act on each piece independently, making it easier for you to know what part of the selector was satisfied.