【发布时间】:2023-03-18 03:30:01
【问题描述】:
我的任务是使用 JavaScript 在单击复选框时启用(打开)并在单击复选框时禁用它(关闭)。 但是,代码仍然不起作用,无论我是否单击复选框,都不会执行任何操作。
</head>
<body>
<div id="container">
<h2> Order Information </h2>
<div class="entry">
Select color:
<select name="color">
<option selected="selected">White</option>
<option>Black</option>
<option>Red</option>
<option>Green</option>
<option>Blue</option>
</select> <br><br>
Select shirt size:
<select name="sizeandprice">
<option>Small - $9.99</option>
<option>Medium - $10.99</option>
<option selected="selected">Large - $11.99</option>
<option>X-Large - $13.99</option>
</select><br><br>
Is this a gift? <input type="checkbox" name="gift"> <br><br>
Write your gift message here: <br>
<textarea disabled rows="5" cols="50" name="message">Type your message here.
</textarea>
</div>
</div>
</body>
</html>
这是 Javascript 代码:
function enable(x) {
x = document.getElementbyId("gift");
x.checked
if(x == true) {
var textarea = document.getElementbyId("message");
textarea.disabled = false;
}
else {
var textarea = document.getElementbyId("message");
textarea.disabled = true;
}
}
【问题讨论】:
标签: javascript html dom checkbox