输入的事件类型

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <input type="text" name="username" id="username" value="" />
        
    <!--<h1></h1>-->
    <script type="text/javascript">
            var inputUser = document.querySelector('#username')
//            var h1 = document.querySelector('h1')
//            //输入事件,一般用于检验输入的数据是否符合规范
            inputUser.oninput = function(e){
                console.log(e)
                if(e.target.value == 'admin'){
                    e.target.style.background = 'skyblue'
                }else{
                    e.target.style.background = 'pink'
                }
//                h1.innerHTML = e.target.value
            }
            
        </script>
    </body>
</html>
原文地址:https://www.cnblogs.com/wwthuanyu/p/10555277.html