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="检测">
  • 相关阅读:
    一种client同步server数据的方案
    nodejs package.json解释
    node.js JS对象和JSON字符串之间的转换
    setInterval的用法
    ActiveMQ 入门Nodejs版
    ActiveMQ + NodeJS + Stomp 极简入门
    为什么 ++[[]][+[]]+[+[]] = 10?
    Child Process模块
    phantomjs 解码url
    PhantomJSのメモいろいろ
  • 原文地址:https://www.cnblogs.com/cfinder010/p/3204612.html
Copyright © 2011-2022 走看看