javascript和radiobuttonlist [英] javascript and radiobuttonlist

查看:85
本文介绍了javascript和radiobuttonlist的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi huys how can i get the selected index of a radiobuttonlist or how i can check if an item in the radiobutton list is actually checked.
Thanks in advance guys.

推荐答案

您需要提供商品ID,以便选择它们,然后您可以检查选中了哪一个.单选按钮列表只是很多单选按钮,不是单个控件.
You need to give your items ids so you can select them, then you can check which one is checked. A radiobutton list is just a lot of radio buttons, it''s not a single control.


您需要访问组(名称属性),然后查找值:

You''ll need to access the group (name attribute) and then look for the values:

<form name="frm1">
 <input type="radio" name="sex" value="male" checked="checked" /> Male<br />
 <input type="radio" name="sex" value="female" /> Female
</form>





// Get the HTMLCollection: getElementsByName
var sex1 = document.getElementsByName('sex');
// or like this
var sex2 = document.forms["frm1"]["sex"];

if (!sex1[0].checked && !sex1[1].checked)
{
 alert('Nothing selected.');
}



据我所知,没有selectedindex,因此您将需要遍历该集合.



As far as I know there is no selectedindex, so you''ll need to loop through the collection.


您可以使用JQuery来做到这一点.以下是我尝试过的完整标记:

You can use JQuery to do this. Below is the complete markup I tried:

<script type="text/javascript" language="javascript" src="jquery-1.6.1.js"></script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head  runat="server">
<script language="javascript" type="text/javascript">


这篇关于javascript和radiobuttonlist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆