原生js实现placeholder 当获取焦点时清空,失去焦点且为空时恢复

<body>
    <input type="text" value="请输入内容" id="text1" />
</body>

<script>
        var oText1=document.getElementById("text1");
        oText1.onfocus=function(){
            if(this.value=="请输入内容"){
                this.value='';
            }
        }
        oText1.onblur=function(){
            if(this.value==''){
                this.value=="请输入内容";
            }
        }
</script>

 

posted @ 2018-10-13 17:33  氧化成风  阅读(1085)  评论(0编辑  收藏  举报