zoukankan      html  css  js  c++  java
  • js 判断checkbox是否选中的实例代码

    分享下js判断是否选中CheckBox的方法。

    代码如下:

    <input type="checkbox" name="checkbox1" checked> 
    <input type="checkbox" name="checkbox1"> 
    <input type="checkbox" name="checkbox1" checked> 
    <input type="checkbox" name="checkbox1"> 
    <input type="checkbox" name="checkbox1"> 
    <script language=javascript> 
    function check(obj) 
    {
    
    for(i=0;i<document.all(obj).length;i++) 
    { 
    if(!document.all(obj)[i].checked)alert("第"+(i+1)+"个没有选择") 
    } //by www.jbxue.com
    } 
    </script> 
    <input type=button onclick="check('checkbox1')" value="检测">
    
    //一个也没有选 
    <input type="checkbox" name="test"> 
    <input type="checkbox" name="test"> 
    <input type="checkbox" name="test"> 
    <input type="checkbox" name="test"> 
    <input type="checkbox" name="test"> 
    <Script Language="JavaScript"> 
    function check(obj){ 
    for(i=0;i<document.all(obj).length;i++){ 
    if(document.all(obj)(i).checked){ 
    return; 
    } 
    } 
    window.alert('一个也没有选!'); 
    } 
    </Script> 
    <input type=button onclick="check('test');" value="检测">
    
    //第几个没有选 
    <input type="checkbox" name="checkbox1" checked> 
    <input type="checkbox" name="checkbox1"> 
    <input type="checkbox" name="checkbox1" checked> 
    <input type="checkbox" name="checkbox1"> 
    <input type="checkbox" name="checkbox1"> 
    <script language=javascript> 
    function check(obj) 
    {
    
    for(i=0;i<document.all(obj).length;i++) 
    { 
    if(!document.all(obj)[i].checked)alert("第"+(i+1)+"个没有选择") 
    } 
    } //by www.jbxue.com
    </script> 
    <input type=button onclick="check('checkbox1')" value="检测">
    
    //一个也没有选 
    <input type="checkbox" name="test"> 
    <input type="checkbox" name="test"> 
    <input type="checkbox" name="test"> 
    <input type="checkbox" name="test"> 
    <input type="checkbox" name="test"> 
    <Script Language="JavaScript"> 
    function check(obj){ 
    for(i=0;i<document.all(obj).length;i++){ 
    if(document.all(obj)(i).checked){ 
    return; 
    } 
    } 
    window.alert('一个也没有选!'); 
    } 
    </Script> 
    <input type=button onclick="check('test');" value="检测">
  • 相关阅读:
    Django 标签过滤器
    Python短路原则
    python学习之路 八 :面向对象编程基础
    python学习之路 七 :生成器、迭代器
    python学习之路 六 :装饰器
    python学习之路 五:函数式编程
    python学习之路 四 :文件处理
    python学习之路 三:字符编码
    机器学习流程管理
    pyspark 自定义聚合函数 UDAF
  • 原文地址:https://www.cnblogs.com/cfinder010/p/3204612.html
Copyright © 2011-2022 走看看