jquery 很靈活,checkbox radio標籤選中的方法有不少,在這兒就例舉三個經常使用的方法。this
一,測試htmlspa
- <div style="margin-top:150px;">
- <input type='checkbox' name='test[]' class='checkbox' value='checkbox1'>checkbox1
- <input type='checkbox' name='test[]' class='checkbox' value='checkbox2'>checkbox2
- <input type='checkbox' name='test[]' class='checkbox' value='checkbox3'>checkbox3
- </div>
- <div style="margin-top:50px;">
- <input type="radio" name="test1" value = "radio1" class='radio' >radio1
- <input type="radio" name="test1" value = "radio2" class='radio' >radio2
- <input type="radio" name="test1" value = "radio3" class='radio' >radio3
- </div>
二,checkbok,radio選中xml
方法1,htm
- $('.checkbox:checked');
- $('input[type^=checkbox]:checked');
方法2,blog
- $('.checkbox').filter(':checked');
方法3ip
- $('.checkbox').each(function(){
- if($(this).is(":checked")){
- alert($(this).val()+": is checked");
- }else{
- alert($(this).val()+": is not checked");
- }
- })
將上面的.checkbox換成.radio,就能夠判斷radio標籤的選中了get