標籤:filter keyword type bar jquery href word log 複製
張映 發表於 2013-07-16
分類目錄: js/jquery
標籤:checkbox, jquery, radio, 選中
jquery 很靈活,checkbox radio標籤選中的方法有很多,在這兒就例舉三個常用的方法。
一,測試html
查看複製列印?
- <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選中
方法1,
查看複製列印?
- //這二個方法屬於一類
- $(‘.checkbox:checked‘);
- $(‘input[type^=checkbox]:checked‘);
方法2,
查看複製列印?
- $(‘.checkbox‘).filter(‘:checked‘);
方法3
查看複製列印?
- $(‘.checkbox‘).each(function(){
- if($(this).is(":checked")){
- alert($(this).val()+": is checked");
- }else{
- alert($(this).val()+": is not checked");
- }
- })
將上面的.checkbox換成.radio,就可以判斷radio標籤的選中了
jquery checkbox radio 標籤 選中的3種方法