使用 jQuery 从 asp:RadioButtonList 读取选定的值 [英] Reading the selected value from asp:RadioButtonList using jQuery

查看:18
本文介绍了使用 jQuery 从 asp:RadioButtonList 读取选定的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有类似下面的代码...

I've got code similar to the following...

<p><label>Do you have buffet facilities?</label>
  <asp:RadioButtonList ID="blnBuffetMealFacilities:chk" runat="server">
    <asp:ListItem Text="Yes" Value="1"></asp:ListItem>
    <asp:ListItem Text="No" Value="0"></asp:ListItem>
  </asp:RadioButtonList></p>
<div id="HasBuffet">
  <p><label>What is the capacity for the buffet?</label>
  <asp:RadioButtonList ID="radBuffetCapacity" runat="server">
    <asp:ListItem Text="Suitable for upto 30 guests" value="0 to 30"></asp:ListItem>
    <asp:ListItem Text="Suitable for upto 50 guests" value="30 to 50"></asp:ListItem>
    <asp:ListItem Text="Suitable for upto 75 guests" value="50 to 75"></asp:ListItem>
    <asp:ListItem Text="Suitable for upto 100 guests" value="75 to 100"></asp:ListItem>
    <asp:ListItem Text="Suitable for upto 150 guests" value="100 to 150"></asp:ListItem>
    <asp:ListItem Text="Suitable for upto 250 guests" value="150 to 250"></asp:ListItem>
    <asp:ListItem Text="Suitable for upto 400 guests" value="250 to 400"></asp:ListItem>
  </asp:RadioButtonList></p>
</div>

我想在收音机列表 blBuffetMealFacilities:chk 更改客户端并在 jQuery 的 HasBuffet div 上执行向下滑动功能时捕获一个事件.创建这个的最佳方法是什么,请记住页面上有几个类似的部分,我希望根据广播列表中的是"或否"回答来揭示问题.

I want to capture an event when the radio list blBuffetMealFacilities:chk changes client side and perform a slide down function on the HasBuffet div from jQuery. What's the best way to create this, bearing in mind there are several similar sections on the page, where I want questions to be revealed depending on a yes no answer in a radio list.

推荐答案

this:

$('#rblDiv input').click(function(){
    alert($('#rblDiv input').index(this));
});

将为您提供单击的单选按钮的索引(我认为,未经测试)(请注意,您必须将 RBL 包装在#rblDiv 中

will get you the index of the radio button that was clicked (i think, untested) (note you've had to wrap your RBL in #rblDiv

然后您可以使用它来显示相应的 div,如下所示:

you could then use that to display the corresponding div like this:

$('.divCollection div:eq(' + $('#rblDiv input').index(this) +')').show();

这是你的意思吗?

另一种方法是给 rbl 一个类名,然后去:

Another approach would be to give the rbl a class name, then go:

$('.rblClass').val();

这篇关于使用 jQuery 从 asp:RadioButtonList 读取选定的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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