当获焦时,文本消失,失焦时文本出现
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
29
30
31
|
<!doctype html>
<html>
<head>
<meta charset= "utf-8" >
<title>无标题文档</title>
</head>
<body>
<input id= "text" type= "text" value= "点我就消失" />
<script>
var oText=document.getElementById( "text" );
var onoff= true ;
oText.color= "#000" ;
oText.onfocus= function (){
if (onoff){
this .value= "" ;
this .color= "red" ;
onoff= false ;
}
}
oText.onblur= function (){
if ( this .value== '' ){
this .color= "#000" ;
this .value= "点我就消失" ;
onoff= true ;
}
}
</script>
</body>
</html>
|