【发布时间】:2013-07-24 01:02:33
【问题描述】:
问题是我有很多文本字段(其中 60-70 个)
而且我需要在未选中复选框时禁用文本输入,并且在选中复选框时启用文本输入。
当取消选中复选框时,它应该禁用该字段并清理它。
【问题讨论】:
-
您使用什么语言/工具包?
-
如果是 jquery 编写你需要帮助的代码
问题是我有很多文本字段(其中 60-70 个)
而且我需要在未选中复选框时禁用文本输入,并且在选中复选框时启用文本输入。
当取消选中复选框时,它应该禁用该字段并清理它。
【问题讨论】:
$('.checkbox').each(function(a,b){
$(b).click(function(){
if($(this).is(':checked')){
$(this).next('.textfield').removeAttribute('disabled');
}else{
$(this).next('.textfield').attr('disabled','disabled').val('');
}
});
});
【讨论】:
这可以使用 javascript 完成。
<html>
<body>
<script type="text/javascript">
function textInput() {
if (document.inputForm.checkbox.checked) {
document.inputForm.input.disabled=false;
} else {
document.inputForm.input.disabled=true;
}
}
</script>
<form name="inputForm">
<label>Enable Input</label>
<input type="checkbox" name="checkbox" onclick="textInput()">
<label> Input:</label>
<input type="text" name="input" disabled="true">
</form>
</body>
</html>
【讨论】: