javascript判斷複選框是否選中的方法,javascript複選框

來源:互聯網
上載者:User

javascript判斷複選框是否選中的方法,javascript複選框

之前總結了一下關於jquery如何判斷複選框是否選中的問題,今天總結如何判斷js複選框是否選中
javascript判斷複選框是否選中,下面通過例子來說明(現在有如下的一組複選框):

<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" />葡萄 

擷取 name=fruit 的一組複選框的值的方法如下:

<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("請先選擇複選框~!");   }else{     alert("複選框的值是:"+checkVal);   } } </script> 

與之前《jquery判斷複選框是否被選中的方法》結合起來一起學習,一定會有意想不到的收穫!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.