Changing background color of text box input not working when empty

前端 未结 8 2103
半阙折子戏
半阙折子戏 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 08:09

    on body tag's onLoad try setting it like

    document.getElementById("subEmail").style.backgroundColor = "yellow";
    

    and after that on change of that input field check if some value is there, or paint it yellow like

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

提交回复
热议问题