我有这两个 html 单选按钮和文本区域。我基本上想在选择"is"时启用文本区域,否则禁用它。
<input type='radio' id='comment' name='comment' value='Yes'>Yes
<input type='radio' id='comment' name='comment' value='No' checked="checked">No
<textarea id='writehere' name='writehere' cols='25' rows='2'></textarea>
下面是我的 jQuery。这些命令仅在我将其放回值“否”时才会发生。但我希望每次更改“注释”时都执行这些命令,无论"is"还是“否”。
$('#writehere').attr('disabled','disabled');
$('#comment').change(function(){
if ($('#comment').val() == 'No')
$('#writehere').attr('disabled','disabled');
if ($('#comment').val() == 'Yes')
$('#writehere').removeAttr('disabled');
});
最佳答案
您有 2 个 id 相同,这就是您的问题。
这不是 W3C 有效的,在这种情况下 jQuery 将只处理第一个 id。
关于jquery - jQuery的change()应该是这样的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9935454/