【发布时间】:2018-09-04 20:35:08
【问题描述】:
我正在尝试实现这一点,当用户选中复选框时,它会启用特定字段,例如 JavaScript 中的 DateTime。
例如,默认情况下 dateTime 是禁用的,直到用户选中 Checkbox,然后 DateTime 才会启用。
这类似于我一直在搜索的内容,用于在用户选中复选框时显示文本:
function myFunction() {
// Get the checkbox
var checkBox = document.getElementById("myCheck");
// Get the output text
var text = document.getElementById("text");
// If the checkbox is checked, display the output text
if (checkBox.checked == true){
text.style.display = "block";
} else {
text.style.display = "none";
}
}
复选框:
<input type="checkbox" id="myCheck" onclick="myFunction()">
<p id="text" style="display:none">Checkbox is CHECKED!</p>
【问题讨论】:
-
请发布您的尝试minimal reproducible example,并具体说明您遇到的问题。
-
你能展示你的 HTML 吗?
-
所以设置 disabled 属性?
标签: javascript grails