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+","; 

                       }

                }

  • 相关阅读:
    http修改443端口,http 强制跳转https
    线程event事件函数实现红绿灯
    信号量设置
    多线程简单实例
    paramiko 实现ssh登录和sftp登录
    在同一台电脑安装python 2 和3,并且怎样安装各自的pip和模块
    ThreadingTCPServer 如何设置端口重用
    Python 变量比较
    python 多线程 并发socket实例
    python 中变量引用问题
  • 原文地址:https://www.cnblogs.com/jpfss/p/9699903.html
Copyright © 2011-2022 走看看