[英]Enable or disable button based on radio button does not work in jQuery?
I have written in aspx file as 我已经写成aspx文件为
<asp:Button ID="btn" runat="server" Text="Add As a Sub Organization" OnClick="lnkChild_Click" ValidationGroup="GroupA" class="btn-u" CausesValidation="true" />
<asp:GridView ID="grdDuplicateOrganisationList" AutoGenerateColumns="false" runat="server" CssClass="table"
DataKeyNames="OrganisationId" GridLines="None">
<Columns>
<asp:TemplateField HeaderText="Organization">
<ItemTemplate>
<div style="text-align: left">
<asp:RadioButton runat="server" ID="rdoOrganisation" GroupName="Child" onclick="javascript:CheckOtherIsCheckedByGVID(this);"></asp:RadioButton>
<%# DataBinder.Eval (Container.DataItem, "Name") %>
</div>
</ItemTemplate>
</asp:TemplateField>
</columns>
</asp:GridView>
<script type="text/javascript">
// function alert() { return confirm("Your Message was sent successfully!") } $(function () { $("[data-toggle='popover']").popover() })
$(function () {
if (!($('#<%= grdDuplicateOrganisationList.ClientID %> tr td').find('input:radio').is(':checked'))) {
$('#<%= btn.ClientID%>').attr('disabled', true).attr('title', 'Select organization then click...');
}
});
$('#<%= grdDuplicateOrganisationList.ClientID %> tr td').find('input:radio').on('change', function () {
if ($(this).is(':checked')) {
$('#<%= btn.ClientID%>').attr('disabled', false).attr('title', '');
} else {
$('#<%= btn.ClientID%>').attr('disabled', true).attr('title', 'Select organization then click...');
}
});
</script>
Now I want that If user will click on radio button then btn should be enabled. 现在,我希望如果用户单击单选按钮,则应启用btn。 The above JavaScript does not work.
上面的JavaScript不起作用。
I haven't any idea about asp but the question is about Jquery so May be I could help you 我对asp没有任何想法,但问题是关于jQuery的,所以我可以为您提供帮助
<input type="radio" name="toggle" value="1">Toggle
<script type="text/javascript">
$("input[name=toggle]").on('click', function() {
var checked = $("input[name=toggle]").prop('checked');
console.log(checked);
if(checked) { $("#yourbtnId").show(); }
else { $("#yourbtnId").hide(); }
</script>
https://jsfiddle.net/o5myvgp9/1/ https://jsfiddle.net/o5myvgp9/1/
Edit
编辑
You can also set it on dom ready 您也可以将其设置为dom
$(function() {
var checked = $("input[name=toggle]").prop('checked');
console.log(checked);
if(checked) { $("#yourbtnId").show(); }
else { $("#yourbtnId").hide(); }
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.