2013-04-11 84 views
2

我的页面中有像“abc_1_2_3_xyz”这样的id元素。如何在JQuery中选择以“abc”开头并以“xyz”结尾的元素?选择以“abc”开头并以“xyz”结尾的元素

$('div[id^="abc"], div[id$="xyz"]'); 
+0

可能重复[这里](http://stackoverflow.com/questions/5376431/ wildcards-in-jquery-selectors) – 2013-04-11 20:08:40

回答

5

您可以使用2个属性选择器。

$('div[id^="abc"][id$="xyz"]'); 
0

使用过滤器:

$('div') 
    .filter(function() { 
     return this.id.match(/^abc+xyz$/); 
    }) 
    .html("Matched!") 
; 
相关问题