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

                       }

                }

  • 相关阅读:
    质数学习笔记
    一本通 1615:【例 1】序列的第 k 个数
    2019.05.09考试解题报告
    洛谷 P1057 传球游戏
    浅谈逆序对
    Set学习笔记
    洛谷 P1115 最大子段和
    洛谷 P1234 小A的口头禅
    About Her
    洛谷 P1164 小A点菜
  • 原文地址:https://www.cnblogs.com/jpfss/p/9699903.html
Copyright © 2011-2022 走看看