• input框失焦时文字消失,聚焦时文字出现


    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
    </head>
    <style>
        input{
            color: #ccc;
        }
    </style>
    <body>
        
        <input type="text" id="input" value="百度几下你都不知道">
        <script>
            var inputValue = '百度几下你都不知道'
            document.getElementById("input").onfocus = function(){
                  if(this.value == inputValue){
                      this.value =  ''
                  } 
            }
    
            document.getElementById("input").onblur = function(){
                  this.value === '' ?  this.value = inputValue : this.value = this.value
            }
    
            document.getElementById("input").oninput = function(){
                   this.style.color = '#000'
            }
        </script>
    </body>
    </html>

    效果:

  • 相关阅读:
    面向对象 & sql语句
    MySQL--数据库面试题汇集
    MySQL优化
    JAVA日报
    JAVA日报
    JAVA日报
    JAVA日报
    JAVA日报
    《大道至简》读后感
    JAVA日报
  • 原文地址:https://www.cnblogs.com/luguankun/p/14367174.html
Copyright © 2020-2023  润新知