button 的鼠标移入问题

img
想给button设置一个鼠标移入的样式改变,移入时判断用户名密码是否为空,为空则显示不能点击button且样式为not-allowed。不为空则设置pointer 可是不为空的时候还是not-allowed??为什么啊

按钮设置为disabled后,设置的onmouseover不会触发了。应该换个思路,按钮默认禁用,给用户名和密码添加blur事件,判断其中一个没值设置按钮不可用,否则可用。
有帮助麻烦点个采纳【本回答右上角】,谢谢~


ID:<input type="text" id="id" /><br />
密码:<input type="text" id="input" />
<input type="button" id="button" disabled /><!--默认禁用--->
<script>
    input.onblur = id.onblur = function () {
        var nums = input.value.length;
        var nums2 = id.value.length;
        var ok = nums > 0 && nums2 > 0;
        button.style.cursor = ok ? 'pointer' : 'not-allowed'
        button.disabled = !ok;
    }
</script>


检查你的代码是否正常运行。
有没有运行到else方法!

用console.log和console.dir调试看看

onmouseover是鼠标移入事件,鼠标移出事件你没有,再来个onmouseout或者直接使用hover事件

还有 == 再加一个= ,数字0改成字符串