显示隐藏文本框内容
作者:互联网
<!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> <body> <input type="" value="手机"> <script> let text = document.querySelector('input') text.onfocus = function(){ // console.log('得到了焦点'); if(this.value == '手机'){ this.value = '' } this.style.color = '#333' } text.onblur = function(){ // console.log('失去了焦点'); if(this.value == ''){ this.value = '手机' } this.style.color = '#999' } </script> </body> </html>
标签:style,console,log,color,text,value,内容,文本框,隐藏 来源: https://www.cnblogs.com/dy-xx-123/p/16465202.html