js 文本框获取丢失焦点

 

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3 <head>
 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 5 <title>js 文本框获取丢失焦点</title>
 6 <script type="text/javascript">
 7   function MM_setTextOfTextfield(objId,x,newText) { //v9.0
 8     with (document){ if (getElementById){
 9       var obj = getElementById(objId);}
10       if (obj){
11         if(obj.value=='' || obj.value=='search here...'){
12           obj.value = newText;
13         }    
14       }
15     }
16   }
17 </script>
18 </head>
19 <body>
20 <form id="form1" name="form1" method="post" action="">
21   <label for="textfield"></label>
22   <input name="textfield" type="text" id="textfield" onfocus="MM_setTextOfTextfield('textfield','','')" onblur="MM_setTextOfTextfield('textfield','','search here...')" value="search here..." />
23 </form>
24 </body>
25 </html>

 

======================================

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3 <head>
 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 5 <title>js 文本框获取丢失焦点</title>
 6 <script type="text/javascript">
 7   function MM_setTextOfTextfield(objId,x,newText) { //v9.0
 8     with (document){
 9       if (getElementById){
10         var obj = getElementById(objId);
11       }
12       if (obj) obj.value = newText;
13     }
14   }
15 </script>
16 </head>
17 <body>
18 <form id="form1" name="form1" method="post" action="">
19   <label for="textfield"></label>
20   <input name="textfield" type="text" id="textfield" onfocus="MM_setTextOfTextfield('textfield','','')" onblur="MM_setTextOfTextfield('textfield','','search here...')" value="search here..." />
21 </form>
22 </body>
23 </html>

 

posted @ 2013-08-28 15:52  竹三戒  阅读(205)  评论(0编辑  收藏  举报