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

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

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

之前總結(jié)了一下關(guān)于jquery如何判斷復(fù)選框是否選中的問(wèn)題,今天總結(jié)如何判斷js復(fù)選框是否選中
javascript判斷復(fù)選框是否選中,下面通過(guò)例子來(lái)說(shuō)明(現(xiàn)在有如下的一組復(fù)選框):

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

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

<script language="javascript"> 
function checkbox(){ 
  var str=document.getElementsByName('fruit'); 
  var strstrLen=str.length; 
  var checkVal=''; 
  for (i=0;i<strLen;i++){ 
    if(str[i].checked==true){ 
      checkVal+=str[i].value+','; 
    } 
  } 
  if(checkVal==''){ 
    alert("請(qǐng)先選擇復(fù)選框~!"); 
  }else{ 
    alert("復(fù)選框的值是:"+checkVal); 
  } 
} 
</script> 

與之前《jquery判斷復(fù)選框是否被選中的方法》結(jié)合起來(lái)一起學(xué)習(xí),一定會(huì)有意想不到的收獲!

相關(guān)文章

最新評(píng)論