zoukankan      html  css  js  c++  java
  • js获取checkbox中所有选中值及input后面所跟的文本

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>js</title>
    </head>
    <script language="javascript">
    function aa(){
        var r=document.getElementsByName("r");  
        for(var i=0;i<r.length;i++){
             if(r[i].checked){
             alert(r[i].value+","+r[i].nextSibling.nodeValue);
           }
        }      
    }
    </script>
    <body>
    <form name="form1" method="post" action="">
    <input type="checkbox" name="r" value="1">a<br>
    <input type="checkbox" name="r" value="2">b<br>
    <input type="checkbox" name="r" value="3">c<br>
    <input type="checkbox" name="r" value="4">d<br>
    <input type="checkbox" name="r" value="5">e<br>
    <input type="checkbox" name="r" value="6">f<br>
    <input type="checkbox" name="r" value="7">g<br>
    <input type="checkbox" name="r" value="8">h<br>
    <input type="checkbox" name="r" value="9">i<br>
    <input type="checkbox" name="r" value="10">j<br>
    <br>
    <input type="button" onclick="aa()" value="button">
    </form>
    </body>
    </html>
    
     
    
    解释:
    nextSibling是获得当前对象的下一个对象
    nodeValue是返回一个节点的值
  • 相关阅读:
    使用Power Shell 拉取项目源代码
    C# 读取excel数据到datatable
    C# 导出datatable数据到excel
    redis过一段时间连接不上
    windows10 docker volume
    通过端口查询到应用
    centos清理磁盘
    maven镜像加速
    IDEA常用插件
    java开发常用软件
  • 原文地址:https://www.cnblogs.com/dekevin/p/5168517.html
Copyright © 2011-2022 走看看