使用jQuery对元素ID进行通配符搜索 [英] Wildcard search of an elements id using jQuery
本文介绍了使用jQuery对元素ID进行通配符搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下内容:
if($("div[id*='*test-*-0-value']").length > 0){
// do stuff
}
不幸的是,通配符*test-*-0-value
无法正常工作.什么是进行搜索的最佳方法,以便我可以测试具有*test-*-0-value
Unfortunatly the wild card *test-*-0-value
isn't working. What's the best way to do a search so that i can test for any ID value that has *test-*-0-value
推荐答案
您可以组合属性选择器,CSS本身也支持 :
You can combine the attribute selectors, which are also natively supported in CSS:
-
[id*='...']
-ID必须包含...
. -
[id$='...']
-ID必须以...
结尾.
[id*='...']
- The id must contains...
.[id$='...']
- The id must end with...
.
代码:
if ($("div[id*='test-'][id$='-0-value']").length) {
// do stuff
}
这篇关于使用jQuery对元素ID进行通配符搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文