zoukankan      html  css  js  c++  java
  • JS中获取页面单选框radio和复选框checkbox中当前选中的值

    单选框:单选框的name值全部相同

                 页面有一组单选框的元素<td><input type="radio name="radioid">满意</td>  <td><input type="radio" name="radioid">基本满意</td>  

                  var radio=document.getElementsByName("radio");

                  var selectvalue=null;   //  selectvalue为radio中选中的值

                 for(int i=0;i<radio.length;i++){

                        if(radio[i].checked==true) {

                                 selectvalue=radio[i].value;

                                 break;

                       }

                }

    多选框:

                   页面有一组单选框的元素<td><input type="checkbox" name="radioid">满意</td>  <td><input type="radio" name="radioid">基本满意</td>  

                  var radio=document.getElementByName("radio");

                  var selectvalue=new Array();   //  selectvalue为radio中选中的值

                  for(int i=0;i<radio.length;i++){

                        if(radio[i].checked==true) {

                                 selectvalue.push(radio[i].value);

                        }

                 }

               或者

             

                var radio=document.getElementByName("radio");

                  var selectvalue="";   //  selectvalue为radio中选中的值

                 for(int i=0;i<radio.length;i++){

                        if(radio[i].checked==true) {

                                 selectvalue=selectvalue+radio[i].value+","; 

                       }

                }

  • 相关阅读:
    PHP 上传文件 function move_uploaded_file: failed to open stream
    python super() 方法使用
    python 负数转为无符号整数
    python Aes 加密 解密
    mongoDB 启动 Error: couldn't connect to server 127.0.0.1:27017 src/mongo/shell/mongo.js:91
    ansible使用
    字段类型binary
    7-14 求整数段和
    7-13 日K蜡烛图
    7-12 两个数的简单计算器
  • 原文地址:https://www.cnblogs.com/jpfss/p/9699903.html
Copyright © 2011-2022 走看看