2010-02-05 23 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已經指出了你正確的方向。