首页 > 解决方案 > 如果 radiobtnlist 的值为 1,我想启用文本框

问题描述

如果 RadioButtonList 的值为零,我有此代码来禁用文本框。但它不工作我不知道为什么。

<script type="text/javascript">
     $(function () {
            $("#RadioButtonList1").change(function() {
              var st = ("#RadioButtonList1").val();
              if (("#RadioButtonList1").val() == "1") {
                   $("#TextBox_ArrivalDate").prop("disabled",false);
              }else{
                  $("#TextBox_ArrivalDate").prop("disabled",true);
              }
            );
       });

</script>

这是我的 RadioButtonList

<asp:Label ID="type" Cssclass="label" runat="server" Text="Please Choose One"></asp:Label>
<asp:RadioButtonList ID="RadioButtonList1" runat="server" style="margin-left: 47px" Width="153px">
    <asp:ListItem Value="1">Round Trip</asp:ListItem>
    <asp:ListItem Value="0">One Way</asp:ListItem>
</asp:RadioButtonList>

标签: javascriptc#jqueryasp.netwebforms

解决方案


将这一行从

$("#RadioButtonList1").change(function() 到 $("<%= RadioButtonList1.ClientID %>").change(function().

ASP.Net 以不同的格式呈现 RadioButton ID。您可以使用此语法访问客户端单选按钮的 id。


推荐阅读