JS取得RadioButtonList的Value,Text及选中值等信息

 

< asp:RadioButtonList ID = " RadioButtonList1 "  runat = " server "
 RepeatColumns
= " 4 "  RepeatDirection = " horizontal " >
    
< asp:ListItem Value = " 1 "  Text = " A1 " ></ asp:ListItem >
    
< asp:ListItem Value = " 2 "  Text = " A2 " ></ asp:ListItem >
    
< asp:ListItem Value = " 3 "  Text = " A3 " ></ asp:ListItem >
    
< asp:ListItem Value = " 4 "  Text = " A4 " ></ asp:ListItem >
</ asp:RadioButtonList >

< input id = " Button1 "  type = " button "  value = " button "  onclick = " fn_GetRadioButtonListInfo(); "   />

 

 


function  fn_GetRadioButtonListInfo()
{
    
//取得RadioButtonList的集合
    var radListItems = document.all("RadioButtonList1");
    
if(radListItems==null)
    
{
         alert(
"相关对象对空");
        
return false;
     }

    
//弹出RadioButtonList的Item的个数
    var radListItesCount = radListItems.length - 1 ;
     alert(
"Item个数"+radListItesCount);
    
    
var radListCheckedValue = "";
    
//遍历Item的Text和Value
    for(var i = 1; i <=   radListItesCount ; i++ )
    
{
        
var itemInfo = "";
         itemInfo 
+= "" + i +"Item ";
        
//Value
         itemInfo += " Value: "+ radListItems[i].value;
        
//Text
        //itemInfo += " Text: "+ radListItems[i].nextSibling.innerText ;
        //或者
         itemInfo += " Text: "+ radListItems[i].parentElement.childNodes[1].innerText ;
        
//是否是选中
         itemInfo += " 是否选中: "+ radListItems[i].checked;
        
//
        if(radListItems[i].checked)
             radListCheckedValue 
= radListItems[i].value;
         alert(itemInfo);
     }

    
if(radListCheckedValue=="")
    
{
         alert(
"没有选中值");
     }

    
else
    
{
         alert(
"选中Value 为 : "+radListCheckedValue);
     }

    
return false;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值