我的代码中有这样一个变量:
var href = $(this).attr('href'),
str = href.split('/').slice(-2,-1)[0];如何检查'images‘、'images-2’或'images-3‘是否与'href’字符串匹配,然后执行一些操作..
发布于 2010-12-01 00:07:41
if href.match(/images(-[23])?/){
doStuf();
}应该能行得通。
发布于 2010-12-01 00:12:40
看看这个:http://api.jquery.com/category/selectors/
你可以像这样:$('href^="images"')
编辑:如果你愿意,你也可以制作你自己的选择器。http://dpatrickcaldwell.blogspot.com/2010/03/custom-jquery-selector-for-external-and.html
James Padolsey已经写了一篇对你有用的文章。http://james.padolsey.com/javascript/regex-selector-for-jquery/
https://stackoverflow.com/questions/4315789
复制相似问题