先看一下效果图点击后然后是离开后
然后是代码,
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> new document </title> <meta name="generator" content="editplus" /> <meta name="author" content="" /> <meta name="keywords" content="" /> <meta name="description" content="" /> <style type="text/css"> </style> </head> <body> <input type="text" id="id1" value="please input cotent" onfocus="test1()" onblur="test2()"> </body> <script type="text/javascript"> function test1(){ var ff=document.getElementById("id1"); ff.value=""; } function test2(){ var ffd=document.getElementById("id1"); ffd.value="please input cotent"; } </script> </html>
主要是通过聚焦失焦设置点击事件,然后通过设置value的值