[英]JS: how to check a button was disabled?
I want to check the button pressed or not pressed. 我要检查按钮是否按下。 How do I can do it?
我该怎么办?
I've already tried to do, but it doesn't work. 我已经尝试过了,但是没有用。 Here's my code.
这是我的代码。
<button onClick="getButton()" id="button2">Disable</button>
<button id="button1">OK</button>
<script>
function getButton() {
document.getElementById('button1').disabled=true;
}
if (getElementById('button1').disabled=true == true) {
document.write("The button was disabled");
}
else {
document.write("No, the button didn't disable");
}
How to check it with if-else statement? 如何用if-else语句检查它?
Thanks in advance. 提前致谢。
function getButton() {
document.getElementById('button1').disabled=true;
document.write("The button was disabled");
}
In your conditional statement, getElementById('button1').disabled=true
should be getElementById('button1').disabled
. 在您的条件语句中,
getElementById('button1').disabled=true
应该是getElementById('button1').disabled
。 The former will always return true
, so you're checking if true
equals true
... 前者将始终返回
true
,因此您要检查true
等于true
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.