2010-02-05 25 views
1

我想选择所有在jQuery中指向swf的标签。我写了下面的代码,哪些工作正常如何在jQuery中进行大小写不敏感的选择?

$(a[href$=".swf"]).each(function(){ 
    alert('hello'); 
}); 

现在,如果我想包括SWF也搜索,什么是最好的方法?

+0

[看到这个请求](http://stackoverflow.com/questions/619621/how-do-i-use-jquery-to-ignore-case-when-selecting) – Sarfraz 2010-02-05 08:30:42

回答

6

您可以查看filter函数。

$('a').filter(function() { 
    return (/\.swf$/i).test($(this).attr('href')); 
}).each(function() { 
    alert('hello'); 
}); 
+0

+1,+也许逃脱点。 return(/\.swf$/i).test($(this).attr('href')); – Alex 2010-02-05 08:37:47

+0

@亚历克斯,谢谢你指出这一点。我已经更新了我的答案。 – 2010-02-05 08:40:35

+0

嘿它的工作..很酷... 我做了这样的事情 $( 'a')的过滤器(函数(){VAR = regexpr /\.SWF$|\.PDF/i。 如果((regexpr).test($(this).attr('href'))) { alert($(this).attr('href')); } }); – Amit 2010-02-05 09:01:08

0

如果你有兴趣的.swf文件和.SWF,您可以使用此:

$('a[href$=".swf"], a[href$=".SWF"]').each(function(){ 
    alert('hello'); 
}); 
1

对于这样一个简单的情况下,为什么不这样做:

$('a[href$=".swf"], a[href$=".SWF"]').each(function(){ 
    alert('hello'); 
}); 

但总的来说,Darin已经指出了你正确的方向。