我已在 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>
现在我希望如果用户单击单选按钮,则应启用 btn。 上面的 JavaScript 不起作用。
最佳答案
我对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/
编辑
你也可以将其设置为domready
$(function() {
var checked = $("input[name=toggle]").prop('checked');
console.log(checked);
if(checked) { $("#yourbtnId").show(); }
else { $("#yourbtnId").hide(); }
});
关于javascript - 基于单选按钮的启用或禁用按钮在 jQuery 中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32649711/