搜索框

搜索框实列

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
             .gg{
                  color:#dddddd;           (浅灰色)
            }
            .bb{
                  color:black;                  (黑色的字体)
             }
    </style>
</head>
<body>
         <input type="text" class="gg" value="请输入内容" onfocus="Focus(this);" onblur="Blur(this);"/>
<script>
     function Focus(ths){
            //查找第一种方式
            //document
            //第二种方式 (this)
            //ths
            ths.className = "bb";
            var current_val = ths.value;
            if(current_val == "请输入内容"){
                ths.value = ""
            }
      }
      function Blur(ths){
            var current_val = ths.value;
            if(current_val == "请输入内容" || current_val.trim().length == 0){
                   ths.value = "请输入内容";
                   ths.className == "gg";
             }
       }
</script>
</body>
View Code

 

posted @ 2016-07-10 23:35  WrYcF  阅读(159)  评论(0编辑  收藏  举报
Live2D