查找选中的单选按钮的值 [英] to find the value of the radio button checked
问题描述
我在转发器中有一个单选按钮列表,转发器在数据列表中.我需要获取所选单选按钮的值.另外,我只需要使用javascript在整个数据列表中选择一个无线电.
hi I have a radio button list inside a repeater , the repeater is inside a Datalist.i need to get the value of the selected radio button. Also I need to select only a single radio in entire datalist using javascript.
推荐答案
您可以使用纯客户端JavaScript进行操作,而不管Repeater,DataList或其他任何内容.
You can do it with pure client side JavaScript regardless of Repeater, DataList or anything.
此代码已在您的页面中
<script type="text/javascript">
function GetSelectedRadioButtonValue(strGroupName) {
var arrInputs = document.getElementsByTagName("input");
for (var i = 0; i < arrInputs.length; i++) {
var oCurInput = arrInputs[i];
if (oCurInput.type == "radio" && oCurInput.name == strGroupName && oCurInput.checked)
return oCurInput.value;
}
return "";
}
</script>
然后要获取所选值,请调用传递单选按钮组的 name
的函数-具有相同名称的所有单选按钮均视为一个组,浏览器将允许用户仅选择其中一个.
Then to get the selected value call the function passing the name
of the radio buttons group - all radio buttons with same name considered a group and the browser will let the user select only one of these.
实时测试用例: http://jsfiddle.net/yahavbr/BL9xJ/
这篇关于查找选中的单选按钮的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!