zoukankan      html  css  js  c++  java
  • 文本框的灰字设置

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title>Document</title>
      <style>
        .gray {
          color: gray;
        }
    
        .black {
          color: black;
        }
      </style>
    </head>
    <body>
      <input type="text" class="gray" value="请输入搜索关键字" id="txtSearch"> 
      <input type="button" value="搜索" id="btnSearch">
      <script>
        // 当文本框获得焦点,如果文本框里的内容是  请输入搜索关键字 清空文本框,并且让字体变为黑色
        
        var txtSearch = document.getElementById('txtSearch');
        // 获取焦点的事件  focus
        txtSearch.onfocus = function () {
          if (this.value === '请输入搜索关键字') {
            this.value = '';
            this.className = 'black';
          }
        }
    
        // 当文本框失去焦点,如果文本框里的内容为空  还原文本框里的文字,并且让字体变为灰色
        // 失去焦点的事件  blur
        txtSearch.onblur = function () {
          // 判断文本框中的内容为空
          // if (this.value === '')
          if (this.value.length === 0 || this.value === '请输入搜索关键字') {
            this.value = '请输入搜索关键字';
            this.className = 'gray';
          }
        }
    
    
    
      </script>
    </body>
    </html>
  • 相关阅读:
    用shareSDK实现的简单分享
    可实现随意切换的button同时随切换改变title的颜色
    创建UITabBarController
    git 常用命令
    实现友盟分享
    IOS 打印语句
    ios 的frame,bound,center
    IOS绘图
    iPhone App 上架流程
    ios 常用字符串的操作
  • 原文地址:https://www.cnblogs.com/jiumen/p/11400167.html
Copyright © 2011-2022 走看看