【问题标题】:Detect whether radio button is disabled or enabled [duplicate]检测单选按钮是禁用还是启用[重复]
【发布时间】:2013-09-29 04:15:36
【问题描述】:
<asp:RadioButtonList ID="rdStatus" onclick="javacript:display();" runat="server" RepeatDirection="Vertical">
<asp:ListItem Text="Temporary Waiver" Value="T" Selected="True"></asp:ListItem>    
<asp:ListItem Text="Never Expires" Value="P"></asp:ListItem>    
<asp:ListItem Text="Expires after the close of:" Value="W"></asp:ListItem>
</asp:RadioButtonList>

function display()
{
    if(radiobuton is enabled)
          //code here
     else
          //code here
}

请提出一些想法来检测锄头来检查单选按钮是禁用还是启用

【问题讨论】:

  • 能否分享生成的html而不是asp代码

标签: jquery asp.net radio-button isenabled


【解决方案1】:

使用jQuery附加到单选按钮列表的点击事件,然后使用jQuery:enabled选择器,像这样:

$('#rdStatus').click(function () {
    if($(this).is(':enabled')) { 
        // Do enabled radio button code here 
    }
    else {
        // Do disabled radio button code here
    }
});

现在您可以删除单选按钮列表标记的 onclick 属性,因为 jQuery 会找到单选按钮列表 (rdStatus) 并为您连接点击事件。

<asp:RadioButtonList ID="rdStatus" runat="server" RepeatDirection="Vertical">

【讨论】:

  • onclick="javacript:display();"这是我必须做的修改
  • @Blossom - 更新了使用 jQuery 事件处理程序而不是使用 onclick 属性的标记的答案。
【解决方案2】:

试试这个:

<asp:RadioButtonList ID="rdStatus"  runat="server" RepeatDirection="Vertical">
<asp:ListItem Text="Temporary Waiver" Value="T" Selected="True"></asp:ListItem>    
<asp:ListItem Text="Never Expires" Value="P"></asp:ListItem>    
<asp:ListItem Text="Expires after the close of:" Value="W"></asp:ListItem>
</asp:RadioButtonList>

$("#<%=rdStatus.ClientID%>").click(function(){
    if($(this).attr('enabled'))
    {
        $(this).removeattr('enabled');
        $(this).attr('disabled',true);
    }
    else
    {
    }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-02
    • 2020-03-28
    • 1970-01-01
    • 2012-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多