嗨,這是送我圈。jquery檢測所選按鈕的ID?
考慮這些單選按鈕:
<input type="radio" class="win" id="50" value="1" name="match1" />
<input type="radio" class="cover" id="50" value="2" name="match1" />
<input type="radio" class="win" id="51" value="1" name="match2" />
<input type="radio" class="cover" id="51" value="2" name="match2" />
<input type="radio" class="win" id="52" value="1" name="match3" />
<input type="radio" class="cover" id="52" value="2" name="match3" />
當提交表單我想知道的任何一個選擇按鈕的ID。
可能根本沒有選擇某些按鈕對。
我想:
for (var x=1; x<4; ++x){
if($('form #'+$(this).attr("id")+'input:radio[name=match'+x+']').prop('checked', true)){
alert('Checked;);
}
}
但它總是evlautes爲true。
謝謝
'id'屬性** **需求是唯一的! (*和他們不應該以一個數字開始,除非你使用html5 *) – 2013-04-11 14:51:33
可能重複[如何檢查單選按鈕是否在javascript中被選中?](http://stackoverflow.com/questions/1423777/how-我可以檢查是否一個單選按鈕被選中在JavaScript) – Nix 2013-04-11 14:52:07