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="检测">
  • 相关阅读:
    Asp.Net 加密 web.config中的某个敏感信息
    异步模型中HttpWebRequest的Timeout
    WCF路由所有的请求到一个方法route all request to one operation
    .Net中直接操作内存
    【转】.NET AJAX实例
    【原】IE/FF 强制浏览器不读取缓存(强制刷新)
    【精】经典的css技巧
    【转】C#如何获取客户端/服务端IP地址
    【原】FireFox显示滚动条 [解决页面左右移动]
    【原】Function Import in Entity Framework 4 issue
  • 原文地址:https://www.cnblogs.com/cfinder010/p/3204612.html
Copyright © 2011-2022 走看看