如何制作a< select>有启用/禁用按钮的选项吗?
选择正确答案时,如何提出一个多项选择问题,可以启用按钮?这是我尝试的:
function enAble() {
let possibleAns = document.getElementById('question').value;
if (possibleAns != 1) {
document.getElementById("btton").disabled = true;
} else if (possibleAns = 1) {
document.getElementById("btton").disabled = false;
}
}
<select id="question" onchange="enAble()">
<option>wrong answer</option>
<option value="1">right answer</option>
<option>wrong answer</option>
</select>
<button id="btton" type="button" disabled>button</button>
How to make a multiple choice question that enables a button when the right answer is selected? Here is what I tried:
function enAble() {
let possibleAns = document.getElementById('question').value;
if (possibleAns != 1) {
document.getElementById("btton").disabled = true;
} else if (possibleAns = 1) {
document.getElementById("btton").disabled = false;
}
}
<select id="question" onchange="enAble()">
<option>wrong answer</option>
<option value="1">right answer</option>
<option>wrong answer</option>
</select>
<button id="btton" type="button" disabled>button</button>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在
中,如果(possibleans = 1){
,(possibleans = 1)
是一个分配语句。使用else if(possibleans == 1){
检查平等。In
else if (possibleAns = 1) {
,(possibleAns = 1)
is an assignment statement. Useelse if (possibleAns == 1) {
to check for equality.更改Possibleans!= 1
对Possibleans!== 1也使用Possibleans === 1
在其他语句中,
Change possibleAns !=1
to possibleAns !==1
Also use possibleAns ===1 in else statement
一种最清洁的编码方式(IMHO)。
A cleanest way to code that (Imho).