zoukankan      html  css  js  c++  java
  • Js 操作radiobuttonlist的方法 (转)

    方法一:

              ‍ function getvalue()
            {
              var b=document.all.rbtid.length
             var a=document.getElementById("rbtid").cells.length;
            //alert(b);结果为5
            //alert(a);结果为4
            //for(var i=0;i<b-1;i++)这样也行
            for(var i=0;i<a;i++)
            {
              var ss="rbtid_"+i;
              var aa=document.getElementById(ss).value;
              //if(eval('document.all.rbtid_'+i).checked==true) //这样也行 eval()函数能将数据符串转成js运行
              var bb=document.getElementById(ss);
              if(document.getElementById(ss).checked) //注意checked不能写成Checked,要不然不成功
               {
                      alert(aa);
                      break;
               }     
           
            }
            }

    方法二:

           var vRbtid=document.getElementById("rbtid");
          //得到所有radio
          var vRbtidList= vRbtid.getElementsByTagName("INPUT");
          for(var i = 0;i<vRbtidList.length;i++)
          {
            if(vRbtidList[i].checked)
            {
               var text =vRbtid.cells[i].innerText;
               var value=vRbtidList[i].value;
               alert("选中项的text值为"+text+",value值为"+value);
            }
          }

    ‍此方法中,RadioButtonList在客户端被看成成了table,通过getElementsByTagName("INPUT")方法获取它的所有子radio,然后循环每个radio,再通过cells获取radio的text值。

    ‍<asp:radiobuttonlist id="rbtid" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 8px" runat="server"
                        Width="216px" Height="176px" name="rbtid">
                        <asp:ListItem Value="0">0</asp:ListItem>
                        <asp:ListItem Value="1" Selected>1</asp:ListItem>
                        <asp:ListItem Value="2">2</asp:ListItem>
                        <asp:ListItem Value="3">3</asp:ListItem>
                    </asp:radiobuttonlist>

    --------------------------------------------------------------------------------------------------------测试

    ‍<script language="javascript" type="text/javascript">
            function test()
            {
                var rb=document.getElementById("rbporperty");
                var rblist=rb.getElementsByTagName("INPUT");
                var tag=0;
                for(var i=0;i<rblist.length;i++)
                {
                    if(rblist[i].checked==false)
                    {
                        //alert("items "+i+"is checked text is"+rb.cells[i].innerText);
                        tag+=1;
                    }
    //                else
    //                {
    //                    alert("null checked");
    //                }
                   
                }
               
                if(tag==rblist.length)
                {
                    alert("no checked");
                }
                else
                {
                    alert("checked!");
                }
               
            }
        </script>

  • 相关阅读:
    codeforces 261B Maxim and Restaurant(概率DP)
    洛谷P3066 [USACO12DEC]逃跑的Barn (线段树合并)
    洛谷P1600 天天爱跑步(线段树合并)
    AtCoder
    SPOJ10606 BALNUM
    洛谷P3567[POI2014]KUR-Couriers(主席树+二分)
    洛谷P2633 Count on a tree(主席树上树)
    【.Net边角料系列】1-单例模式(我真不是你想的那样)
    生成二维码的开源工具对比(附源码了呀!)
    你所不知道的linq(二)
  • 原文地址:https://www.cnblogs.com/Godblessyou/p/1927571.html
Copyright © 2011-2022 走看看