如果未选中复选框,则尝试将表单控件属性返回为“启用”。 因此,对于这个 HTML 片段:
<div id="post">
<div class="Response">
<label><input type="radio" name="Radio402" value="Y" id="R402Y" onchange='radioChange(this, "402")'>Yes</label>
</div>
<div class="responseDetails">
<div class="Observation">
<label for="Obs402">Observation:</label>
<textarea name="observation" id="Obs402" rows="6" disabled></textarea>
</div>
<div class="DueDate">
<label for="DueDate402">Due date:<br></label>
<input name="DueDate" class="DueDate_in" type="text" id="DueDate402"/>
</div>
<div class="actions">
<label for="pa402">Actions required to correct and/or prevent this observation:</label>
<textarea name="actions" id="pa402" rows="6"></textarea>
</div>?
</div>
</div>
<label for="item">Check me</label>
<input type="checkbox" id="item"/>
我正在应用这个JS
$(document).ready(function()
{
if($("#item").click(function()
{
$("#post").prop("disabled", true);
}));
else
{
$("#post").prop("disabled", false);
};
});
也尝试过
$("#item").change(function(){
if (this.checked) {
$("#post").prop("disabled", true);
} else {
$("#post").prop("disabled", false);
}
});
如果选中,它将被禁用,但如果未选中,它将保持禁用状态。我究竟做错了什么?我还尝试了change(function)()
。我感觉 JS 没有看到取消选中事件,因此不会返回该属性。提前致谢。
更新:哦伙计们,忘了提一下,有一个 textarea 元素默认保持禁用状态,并由其他地方的 radiobtn 控制。当未选中该框时,此文本字段不应启用。
最佳答案
您想使用:checked
$('#item').on('click', function(){
$("#post").prop("disabled", $(this).is(':checked'));
});
关于javascript - 未选中返回盒子上的属性(property),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22268346/