2012-01-25 33 views
20

鑑於以下html,是否有一個選擇器允許我基於type獲取兩個選項?用於多個值的jQuery屬性選擇器

<input type="text" /> 
<input type="button" /> 

 

$('input[type=text || button]'); //for example, double pipes as an OR does not work 

我通過文檔去了,但我無法找到使用邏輯運算符的能力或提供匹配列表的意味着什麼。

+3

的可能重複[Jquery的:更清潔的方式通過multple可能屬性值來選擇(http://stackoverflow.com/questions/5471775/jquery-cleaner-way-to-select-by-multple-possible-attribute-values) –

回答

31

這應有助於:

$('input[type="text"], input[type="button"]'); 
+1

真的沒有更好的解決方案嗎?我擔心與「value1 | value2」解決方案相比,這可能會帶來一點問題,但CSS3中沒有其他方法,所以我開始搜索。那麼,我只希望jQuery在優化方面做得最好。 – Kiruse