javascript - 选择单选按钮时启用单击按钮

标签 javascript jquery asp.net

我有一个由 ListView 动态生成的单选按钮列表。用户选择一个单选按钮并单击“更新”按钮来更新其数据。我想保持按钮禁用,直到用户做出选择。我怎样才能做到这一点?

<asp:ListView ID="ListView1" runat="server" DataKeyNames="ID_BG" DataSourceID="SqlDataSource_BGlist">
            <ItemTemplate>
                <itemtemplate>                
            <label><input id="Radio1" name="BG_list" type="radio" runat="server" value='<%# Eval("BG_fileName") %>'/>
                <img alt="" style="width:150px" src="/Members/images/BG/icons/<%# Eval("BG_fileName") %>"></label>                 
        </itemtemplate> ....



    <asp:Button disabled="disabled" CssClass="btn btn-default" ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Change" OnClientClick="return confirm('Are you sure you want to change your Background Image?');" />

最佳答案

再见格洛丽亚,

您应该添加 jQuery,然后在 header 中添加这段代码:

$(function () {
  $("input[id*='Radio1']").click(function () {
    $("#<%=UpdateButton.ClientID %>").removeAttr('disabled');
  });
});

让 ASP.NET 取代 <%=UpdateButton.ClientID %>使用控件的实际 ID,您必须将 head 启用为服务器端控件,否则 ASP.NET 将不会检查 <head> 的内容既不嵌套<script>标签:

<head runat="server">
  <script>

    // server-side variant JS with ASP.NET <%= tags %>

  </script>
</head>

有关此主题的更多信息:Understanding the runat server attribute

关于javascript - 选择单选按钮时启用单击按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25034756/

相关文章:

javascript - 在 d3 中应用转换时出现错误

c# - MVC 2 需要什么版本的 .net?

c# - 为什么我不能在没有 runat=server 的情况下绑定(bind)可见的控件?

javascript - 两个 .js 文件的 GetScriptDescriptors() 方法 : strange unexpected behavior

javascript - 在 promise 解决后按文件执行独特的操作

javascript - 如何在 javascript (ES5/6) 中计算圆括号(圆括号)

javascript - 当我们在顶部有一个持久的栏时 anchor 链接

javascript - 点击事件在 dcmads 上不起作用

JavaScript 加载时间简写

javascript - React-Native 在按下通知后导航