知识点
代码
<input type = "text" class = "inputBox"><button disabled="true">按钮</button><script>var inputBox = document.querySelector(".inputBox"); //获取输入框var btn = document.querySelector("button"); //获取按钮inputBox.onkeyup=function(){ //键盘松开事件var value = inputBox.value; //赋值if(value){ //判断,六种假值的隐式转换中的""btn.disabled = false; //Input有值时按钮禁用效果取消}else{btn.disabled = true; //input为空字符串时禁用效果生效}}</script>
