js获取RadiobuttonList的选中项
来源:互联网 发布:shopnc软件版权问题 编辑:程序博客网 时间:2024/05/19 15:42
1、以前,用javascript获取DropDownList的选中项的值,直接用如下代码:
document.getElementById("DropDownList1").options[document.getElementById("DropDownList1").options.selectedIndex].value
这次取RadioButtonList想当然的就这么用了,然而不凑效,呵呵,凑效就怪了。
查看了一下网页源文件,发现,DropDownList在html里的代码是:
<select name="DropDownList1" id="DropDownList1">
<option value="1">一</option>
<option selected="selected" value="2">二</option>
</select>
而RadioButtonList的源代码是:
<table id="Rbl_IsSM" class="RadioButtonList" onclick="SelectVisible()" border="0" style="border-color:#D0D0BF;border-width:1px;border-style:Double;height:95%;width:90%;">
<tr>
<td><input id="Rbl_IsSM_0" type="radio" name="Rbl_IsSM" value="1" /><label for="Rbl_IsSM_0">是</label></td>
</tr><tr>
<td><input id="Rbl_IsSM_1" type="radio" name="Rbl_IsSM" value="0" checked="checked" /><label for="Rbl_IsSM_1">否</label></td>
</tr>
</table>
被解析成了table.每一项的格式也如上。
所以获取选中项只能用循环解决了,如下:
var b = 0;
var icount = document.getElementById("Rbl_MixNum").cells.length;
for(var i = 0; i < icount; i ++)
{
var ss="Rbl_MixNum_"+i;
if(document.getElementById(ss).checked)
{
b = document.getElementById(ss).value;
break;
}
}
也不知道还有没有更好的方法。
2、而给RadioButtonList 添加事件时,我想是改变选择项则触发客户端事件,结果添加onchange事件,没反应。不知何故?而用oncilck事件则达到了预期的效果。
- js获取RadiobuttonList的选中项
- JS获取RadioButtonList的选中值
- JS如何获取RadiobuttonList的选中值
- js获取RadioButtonList选中值
- 学习Jquery - 获取RadioButtonList中Radio项的选中值
- js验证RadioButtonList是否选中
- JS判断RadioButtonList是否选中
- JS 获取radiobuttonlist checkboxlist的值
- js获取RadioButtonList的选值
- 用javascript获取asp.net中RadioButtonList的选中值
- 用javascript获取asp.net中RadioButtonList的选中值
- 用javascript获取asp.net中RadioButtonList的选中值
- jquery 获取 GridView 或 Repeater 里边的 RadioButtonList 选中值
- Js得到radiobuttonlist选中值的两种方法
- Js得到radiobuttonlist选中值的两种方法
- js获取radiobuttonlist值
- Javascript中获取RadioButtonList中的子项是否被选中
- yii radioButtonList默认选中项
- 多线程+socket+文件读写(面)
- ExtJs Store baseParams设置
- 回车与换行的区别
- 多线程+socket+文件读写(面)
- 堆的排序
- js获取RadiobuttonList的选中项
- 2010年软件设计师考试注意事项
- 堆的排序
- 多线程+socket+文件读写(面)
- 堆的排序
- Windows 2003安装iis,设置iis
- MyEclipse在线安装svn插件
- 软件客户需求权利书,软件客户需求义务书
- 有关EVC SP4,VS2005 两种建立MFC程序的随笔