[英]Enable click button when a radio button is selected
我有一個由列表視圖動態生成的單選按鈕列表。 用戶選擇一個單選按鈕,然后單擊“更新”按鈕以更新其數據。 我想讓按鈕保持禁用狀態,直到用戶做出選擇為止。 我該怎么做?
<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?');" />
嘗試以下操作:使用.on()
作為動態生成的單選按鈕,將change
事件綁定到單選按鈕,並在其中啟用更新按鈕。
$(function(){
$(document).on('change','input[name="BG_list"]',function(){
$('#UpdateButton').removeAttr('disabled');
});
});
編輯 -使用更新按鈕ID,例如$("#<%=UpdateButton.ClientID %>").removeAttr('disabled');
如@pid答案中所述。 由於我不是asp.net開發人員,因此不知道實際ID可能有所不同。
Ciao Gloria,
您應該添加jQuery,然后在標頭中添加以下代碼:
$(function () {
$("input[id*='Radio1']").click(function () {
$("#<%=UpdateButton.ClientID %>").removeAttr('disabled');
});
});
若要使ASP.NET用控件的實際ID <%=UpdateButton.ClientID %>
,必須將head作為服務器端控件,因為ASP.NET否則將不檢查也不嵌套的<head>
的內容<script>
標簽:
<head runat="server">
<script>
// server-side variant JS with ASP.NET <%= tags %>
</script>
</head>
有關此主題的更多信息,請參見 : 了解runat服務器屬性
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.