欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jquery判斷復(fù)選框是否被選中的方法

 更新時間:2015年10月16日 14:31:42   投稿:lijiao  
這篇文章主要介紹了jquery判斷復(fù)選框是否被選中的方法,需要的朋友可以參考下

jquery 判斷復(fù)選框是否選中以及如何選中的問題做一下總結(jié)。
進入正題,還是當(dāng)頁面有如下一組復(fù)選框的時候:

<input type="checkbox" name="fruit" value="apple" />蘋果 
<input type="checkbox" name="fruit" value="orange" />橘子 
<input type="checkbox" name="fruit" value="banana" />香蕉 
<input type="checkbox" name="fruit" value="grape" />葡萄 

那么使用 Jquery 獲取 name=fruit 的一組復(fù)選框的值的方法如下:

var checkVal=''; 
$("input[name='fruit']:checkbox").each(function(){ 
  if($(this).attr('checked')){ 
    checkVal+=$(this).val()+','; 
  } 
}) 
判斷 name=fruit 組的復(fù)選框是否有被選中的選項:
var flag=false; 
$("input[name='fruit']:checkbox").each(function(){ 
  if($(this).attr('checked')){ 
    flag=true; 
  } 
}) 
if(flag){ 
  alert('有被選中'); 
}else{ 
  alert('沒有選中任何選項'); 
} 

以上就是jquery判斷復(fù)選框是否被選中的方法,希望對大家的學(xué)習(xí)有所幫助,還有用js獲取的,請參考《JS判斷復(fù)選框是否選中實例》

相關(guān)文章

最新評論