jquery启用/禁用基于radiobutton的文本框
在我的页面(jsp)中,我有一个radiobutton组和一个文本框(最初被禁用)。
- 每当用户点击单选按钮时,应启用文本框
- 当用户点击其他一些单选按钮时,文本框应再次被禁用。
我可以使用下面的代码启用最初禁用的复选框。
$("#DevGroup_OTHER").click(function(){ $("#otherDevText").attr("disabled",""); })
我的问题:
- 但是我怎样才能再次禁用文本框?
- 使用jQuery有更简单的解决方案吗?
问候
始终禁用它(对于每个单选按钮),如果单选按钮是启用文本框的单选按钮,则重新启用它。 除非用户使用1980年制造的机器,否则它将如此之快,而不是人们所知道的。
$('radio').click(function() { $("#otherDevText").prop("disabled",true); if($(this).attr('id') == 'enable_textbox') { $("#otherDevText").prop("disabled",false); } });
或者,如果有多个单选按钮将启用文本框:
$('input:radio').click(function() { $("#otherDevText").prop("disabled",true); if($(this).hasClass('enable_tb')) { $("#otherDevText").prop("disabled",false); } });
$("#some_other_radiobutton").click(function(){ $("#otherDevText").attr("disabled","disabled"); });