jQuery查找以定义的字符串开头并以数字结尾的所有id [英] jQuery find all id's that begin with a defined string and end in a number
本文介绍了jQuery查找以定义的字符串开头并以数字结尾的所有id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想做类似的事情:
jqueryElement.find('divIdWithIterator**').each(...);
其中'divIdWithIterator **'
匹配所有包含以'divIdWithIterator'
开头的ID的元素,以数字结尾,例如:
where 'divIdWithIterator**'
matches all elements with ids that start with 'divIdWithIterator'
and end in a number, such as:
divIdWithIterator1,divIdWithIterator2,divIdWithIterator26
在jQuery中执行此操作的好方法是什么?
What is a good way to do this in jQuery?
谢谢!
推荐答案
不幸的是,没有正则表达式选择器。
Unfortunately, there is no regular expression selector.
您可以使用 attribute-starts-with选择器 ,然后过滤结果并使用 search()
You could use the attribute-starts-with selector, then filter the results and check for numeric endings using search()
例如
var divs = jqueryElement.find('[id^="divIdWithIterator"]').filter(function(index){
return this.id.search(/\d$/) != -1;
});
这篇关于jQuery查找以定义的字符串开头并以数字结尾的所有id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文