Javascript 使用客户端脚本处理RadioButtonList
我有一个ASP RadioButtonList,我想在客户端处理它 该网页包含一个带有单选按钮组和关联GridView的表单。当用户选择其中一个单选按钮时,我想隐藏或显示GridView上的行。(行必须隐藏,而不是通过回发从数据集中过滤出来,因为在用户提交表单时会进行处理。) 多亏了StOf和其他网站,这里是我目前所拥有的 我的客户端脚本由于无法识别Javascript 使用客户端脚本处理RadioButtonList,javascript,jquery,asp.net,radiobuttonlist,client-side-scripting,Javascript,Jquery,Asp.net,Radiobuttonlist,Client Side Scripting,我有一个ASP RadioButtonList,我想在客户端处理它 该网页包含一个带有单选按钮组和关联GridView的表单。当用户选择其中一个单选按钮时,我想隐藏或显示GridView上的行。(行必须隐藏,而不是通过回发从数据集中过滤出来,因为在用户提交表单时会进行处理。) 多亏了StOf和其他网站,这里是我目前所拥有的 我的客户端脚本由于无法识别值而出错(“无法读取未定义的属性'Value')) 设计时我的RadioButton列表: <asp:RadioButtonList ID="
值而出错(“无法读取未定义的属性'Value'))
设计时我的RadioButton列表:
<asp:RadioButtonList ID="RadioButtonList1" runat="server" onclick="javascript:update_grid( this );>
<asp:ListItem Selected="True" Value="All">Show All</asp:ListItem>
<asp:ListItem Value="Hide">Hide Checked</asp:ListItem>
<asp:ListItem Value="Show">Show Only Checked</asp:ListItem>
</asp:RadioButtonList>
试着这样做:
$(function(){
$("#RadioButtonList1 input[id^=Radio]").click(function(){
alert(this.value);
})
});
工作小提琴:打开调试控制台,检查jQuery选择器…$('RadioButtonList1')[]
(不,我不知道这是什么意思。但我猜它的意思是“找不到对象”)。你需要这样处理这些无线电:@RobertRozas:Ooh,闪亮!当我在我的项目中使用它时,请给出一个答案。@CodeswithHammer,done:)我想知道为什么这种方法有效,以及为什么我尝试的前两种方法无效。这是一个搜索div id的过程,然后在div内的每个单选按钮上设置一个click处理程序……而不是alert(this.value)
您应该能够使用警报($(this.val())代码>太。。
<table id="RadioButtonList1" onclick="update_grid(this);">
<tr>
<td><input id="RadioButtonList1_0" type="radio" name="RadioButtonList1" value="All" checked="checked" /><label for="RadioButtonList1_0">Show All</label></td>
</tr><tr>
<td><input id="RadioButtonList1_1" type="radio" name="RadioButtonList1" value="Hide" /><label for="RadioButtonList1_1">Show Unchecked</label></td>
</tr><tr>
<td><input id="RadioButtonList1_2" type="radio" name="RadioButtonList1" value="Show" /><label for="RadioButtonList1_2">Show Only Checked</label></td>
</tr>
</table>
$(document).ready(function () {
$('#RadioButtonList1_All').on('change', function () {
$("#tbl tr").show();
});
$('#RadioButtonList1_Hide').on('change', function () {
var grd = $("#my_gridview");
var rows = $("#my_gridview tr:gt(0)");
var rowToShow = rows.find("td:eq(0)").filter(chk_ischecked == false);
rows.show().not(rowToShow).hide();
});
$('#RadioButtonList1_Show').on('change', function () {
var grd = $("#my_gridview");
var rows = $("#my_gridview tr:gt(0)");
var rowToShow = rows.find("td:eq(0)").filter(chk_ischecked == true);
rows.show().not(rowToShow).hide();
});
});
$(function(){
$("#RadioButtonList1 input[id^=Radio]").click(function(){
alert(this.value);
})
});