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="检测">
  • 相关阅读:
    面试题63 二叉搜索树的第k个结点
    面试题62 序列化二叉树
    面试题61 把二叉树打印成多行
    面试题60 按之字形顺序打印二叉树
    centos下Nginx代理访问web服务
    回文数
    两数之和--哈希表unordered_map
    删除链表的倒数第N个节点---链表的应用
    基础篇,排序(冒泡排序,快速排序)
    linuxC网络聊天室简单代码,CSDN博客迁移
  • 原文地址:https://www.cnblogs.com/cfinder010/p/3204612.html
Copyright © 2011-2022 走看看