2011-01-12 28 views
0

我想針對一組單選按鈕的那名包含字符串的一部分...jQuery的:單選按鈕名稱中包含字符串

if (!$("input:radio[name=PercentageValue]:checked")) 
    alert("you need to check a percentage"); 

這是不工作...

+0

如果你能發佈HTML爲好,這很可能是有益的。 – Ktash 2011-01-12 18:05:49

回答

2

jQuery的包含選擇是~=

http://api.jquery.com/attribute-contains-word-selector/

此外,$("input:radio[name=PercentageValue]:checked")永遠是true,嘗試使用.is(":checked")將返回一個布爾值,像這樣:

if (!$("input:radio[name=~'PercentageValue']").is(":checked")) 
    alert("you need to check a percentage"); 
0

嘗試

if (!$("input:radio[name=PercentageValue]:checked").length) 
    alert("you need to check a percentage"); 
相關問題