本文介绍了ASP C#服务器端/客户端中的html单选按钮(在相同的组名下)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获取选定的单选按钮项服务器端?
我有5个具有唯一ID的单选按钮,并且具有runat =''服务器的相同组名,
如何在单选按钮组中的服务器端和javascript中获取选定的单选按钮.
由于设计问题,我无法使用asp:radiobuttonlist,
所以我前往html单选按钮.
如何获取服务器端(C#)和客户端(Javascript/Jquery)的选定单选按钮
感谢任何建议.
How to get the selected radio button item server side?
I have 5 radio buttons with unique ids and same group name with runat=''server'',
How to get selected radio button in server side and javascript too among the radio button group.
I can''t go for asp:radiobuttonlist, due to design issues, \
so I head for html radio buttons.
How can I get the selected radio button, both server side(C#) and client side(Javascript/Jquery)
any suggestion is appreciated.
推荐答案
function getCheckedRadio(radio_group) {
for (var i = 0; i < radio_group.length; i++) {
var button = radio_group[i];
if (button.checked) {
return button;
}
}
return undefined;
}
var checkedButton = getCheckedRadio(document.forms.frmId.elements.groupName);
if (checkedButton) {
alert("The value is " + checkedButton.value);
}
这篇关于ASP C#服务器端/客户端中的html单选按钮(在相同的组名下)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!