0

这是隐藏 ID 为 .style2 的表格单元格的 jquery 代码:

 $('#myRadioButtonList').change(function() {

    if ($(this).attr('checked') == true && $(this).val() == "HB") {
        $('.style2').hide("slow");
    };
   });

这是我的单选按钮列表

     <asp:RadioButtonList ID="myRadioButtonList" runat="server">
         <asp:ListItem Selected="True" Value="HB">None</asp:ListItem>
         <asp:ListItem Value="HOBSKS">Service </asp:ListItem>
         <asp:ListItem Value="OBAKS">Open Service</asp:ListItem>
         <asp:ListItem Value="BBKS">Close Service</asp:ListItem>
     </asp:RadioButtonList>

我受到这个话题的启发

使用带有 RadioButtons 的 JQuery 来隐藏/显示表格行

这样我的jquery不起作用,部分有错误

if ($(this).attr('checked') == true && $(this).val() == "HB") 

我单独尝试了上面的这两个条件,它们都不起作用。我需要使用我的单选按钮,但似乎我做不到。那么我应该如何编写该部分以使我的代码正常工作。

谢谢。

4

2 回答 2

2
if ( ($(this).attr('checked') == true) && ($(this).val() == "HB") )

正如大卫所说的那样,布尔运算符可能就是这样做的,但是将 () 放在任何可能会绊倒您的大脑或浏览器的短语周围也是很好的。

更新哦,您的 $(this) 指向列表,而不是列表项。尝试更改选择器以匹配将更改的项目的 HTML 输出。

更新 2看起来您需要更改初始选择器。现在你正在监听整个表格/列表的变化——你想监听列表中所有单选按钮的变化。所以尝试 $("#myRadioButtonList input[type=radio]") 代替。

于 2010-03-03T13:38:26.083 回答
0

可能是您使用的是单个“&”,请尝试使用“&&”作为布尔运算符

if ($(this).attr('checked') == true && $(this).val() == "HB") 
于 2010-03-03T13:37:58.957 回答