Javascript Jquery收音机和文本框
在我的Jsp中,我有两个单选按钮rb1和rb2以及两个文本框txt1和txt2 如何在选中rb2时禁用文本框txt2 这是我的密码:Javascript Jquery收音机和文本框,javascript,jquery,html,css,Javascript,Jquery,Html,Css,在我的Jsp中,我有两个单选按钮rb1和rb2以及两个文本框txt1和txt2 如何在选中rb2时禁用文本框txt2 这是我的密码: <asp:TextBox runat="server" ID="txt1""></asp:TextBox> <asp:TextBox runat="server" ID="txt2"></asp:TextBox> <asp:RadioButton ID="rb1
<asp:TextBox runat="server" ID="txt1""></asp:TextBox>
<asp:TextBox runat="server" ID="txt2"></asp:TextBox>
<asp:RadioButton ID="rb1" Text="hello" runat="server" />
<asp:RadioButton ID="rb2" Text="world" runat="server" />
您可以使用。从jQuery更改事件:
$("#<%= rb2.ClientID %>").change(function() {
$("#<%= txt2.ClientID %>").prop("disabled", this.checked);
});
您可以使用。从jQuery更改事件:
$("#<%= rb2.ClientID %>").change(function() {
$("#<%= txt2.ClientID %>").prop("disabled", this.checked);
});
将其绑定到更改事件
另外,由于控件具有runa=server属性,请确保使用属性contains选择器
不要忘记将代码包含在DOM就绪处理程序中。将其绑定到更改事件
另外,由于控件具有runa=server属性,请确保使用属性contains选择器
不要忘了将代码包含在DOM就绪处理程序中。这里最好使用事件委派
$(document).on('change', '[id^="rb"]', function() {
var txt = $("#txt" + event.target.id.split(/rb/)[1]);
txt.prop('disabled', this.checked) :
});
任何单选按钮更改时,都会找到并禁用相应的输入框。最好在此处使用事件委派
$(document).on('change', '[id^="rb"]', function() {
var txt = $("#txt" + event.target.id.split(/rb/)[1]);
txt.prop('disabled', this.checked) :
});
任何单选按钮更改时,都会找到并禁用相应的输入框。如果您不喜欢ASP.NET要求解析元素Id,可以在项目的配置中更改。system.web->pages clientIDMode=Static。将导致.Net不为您生成Id,而是使用您分配给控件的Id。如果您不喜欢ASP.Net要求解析元素Id,可以在项目的配置中更改该Id。system.web->pages clientIDMode=Static。将导致.Net不为您生成Id,而是使用您分配给控件的Id。