<input type = "text" id = "Height">
<button type = "button" id = "Work!" disabled = "true"> Work! </button>
<script>
var Height = document.getElementById("Height");
var Button = document.getElementById("Work!");
Height.addEventListener("input",function() {
if(Height.value!= "") {
Button.disabled = false;
} else {
Button.disabled = false;
}
});
我不明白为什么当用户在输入字段中输入一个值时从未启用该按钮。我花了2+小时尝试每种可能的组合。我的盐水平现在不在屋顶,任何帮助将不胜感激。如何使用javascript dom事件--- addEventListener
因为您在'if'的两个分支中都将'Button.disabled'设置为'false'? – 2016-11-26 03:58:14
这和其中一个,你有一个大写的D'禁用'D –
您使用哪个浏览器?它在Chrome中工作正常(在我将'Button.Disabled'更改为'Button.disabled' - 带有小'd'后) –