js添加水印文字


字)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function watermark(id,value)
{
   var obj =  document.getElementById(id);
   obj.value = value;
   obj.style.cssText = "color:#ccc";
   //獲取焦點事件
   obj.onfocus = function()
   {
       this.style.cssText = "color:#333";
       if(this.value==value)
       {
           this.value = '';  
       }
   };
   //失去焦點事件
   obj.onblur = function()
   {
       if(this.value=="")
       {
         this.value = value;
         this.style.cssText = "color:#ccc";
       }
       else
       {
         this.style.cssText = "color:#333";
       }
   };
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章