Changing background color of text box input not working when empty

前端 未结 8 2043
半阙折子戏
半阙折子戏 2020-12-29 07:37

I am having a tough time with this javascript code to change the background color of a text input if the input is empty.

Here is the code:

function c         


        
8条回答
  •  [愿得一人]
    2020-12-29 07:45

    Don't add styles to value of input so use like

    function checkFilled() {
        var inputElem = document.getElementById("subEmail");
        if (inputElem.value == "") {
            inputElem.style.backgroundColor = "yellow";
                    }
            }
    

提交回复
热议问题