如何在选择radiobuttonlist时启用文本框是在asp.net中使用jquery而不使用autopostback = true

时间:2010-06-06 02:38:52

标签: asp.net

<asp:RadioButtonList ID="RdoBtnHasNotified" runat="server" 
  RepeatDirection="Horizontal" AutoPostBack="True" 
  OnSelectedIndexChanged="RdoBtnHasNotified_SelectedIndexChanged">
<asp:ListItem Value="1">Yes</asp:ListItem>
<asp:ListItem Value="0" Selected="True">No</asp:ListItem>
</asp:RadioButtonList></td>

<asp:TextBox ID="TxtHowNotified" runat="server" TextMode="MultiLine" MaxLength="100"></asp:TextBox></td>

2 个答案:

答案 0 :(得分:0)

这应该可以解决问题:

$('#<%= RdoBtnHasNotified.ClientID =%>').click() {
   if ($(this).find('input:checked').val()) == 'Yes' {
      $('#idOfYourTextBox').attr('enabled','true');
   }
}

答案 1 :(得分:-1)

<asp:RadioButtonList ID="rbl" runat="server" onclick="Toggle()">
  <asp:ListItem Value="0">No</asp:ListItem>
  <asp:ListItem Value="1">Yes</asp:ListItem>
</asp:RadioButtonList>


<asp:TextBox ID="TextBox1" runat="server" style="display:none" />

JS

<script type="text/javascript">


 function Toggle()
 {
     var radio = document.getElementsByName('<%=rbl.ClientID %>');
     var txt = document.getElementById('<%=TextBox1.ClientID %>');
        for (var j = 0; j < radio.length; j++)
        {
           if (radio[j].checked)
           {
                if(radio[j].value == '1')
                {
                    txt.style.display = '';
                }
                else
                {
                   txt.style.display = 'none';
                }
            }
        }
 }
</script>