[英]Jquery Radio and text boxes
在我的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" Text="hello" runat="server" />
<asp:RadioButton ID="rb2" Text="world" runat="server" />
您可以使用jQuery中的.change
事件:
$("#<%= rb2.ClientID %>").change(function() {
$("#<%= txt2.ClientID %>").prop("disabled", this.checked);
});
将它绑定到更改事件
$('[id*=rb2]').on('change', function() {
var txt = $('[id*=txt2]');
txt.prop('disabled', this.checked) :
});
另外因为控件具有runa=server
属性,所以请确保使用属性contains selector。
并且不要忘记将代码包含在DOM
就绪处理程序中。
最好在这里使用事件委托。
$(document).on('change', '[id^="rb"]', function() {
var txt = $("#txt" + event.target.id.split(/rb/)[1]);
txt.prop('disabled', this.checked) :
});
只要任何单选按钮发生变化,就会找到并禁用相应的输入框。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.