js 用户输入

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <style>
        .search{
            width: 350px;
            height: 30px;
            margin: 100px auto;
            position: relative;

        }
        .search input{
            width: 200px;
            height: 25px;

        }

        .search label{
            font-size: 12px;
            color: #CCCCCC;
            position: absolute;
            top: 8px;
            left: 20px;
            cursor: text;
        }



    </style>

    <script>
        window.onload=function(){
            function $(id){
                return document.getElementById(id);            
             }
            $("txt").focus();/*自动获取焦点*/
            $("txt").oninput = function(){

                if(this.value == ""){
                    $("message").style.display="block";
                }
                else{
                    $("message").style.display="none";

                }

            };

        }

    </script>


</head>
<body>

<div class="search">
    <input type="text" id="txt" />
    <label for="txt" id="message">淘宝淘宝</label>

</div>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/weixin_44119660/article/details/86669210