<!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> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>无标题文档</title> <head> <script src="jquery.min.js"></script> <!--<script> $(function(){ $("#username").focus(function(){ var username_value=$(this).val(); //不能提出来。提到第一句只执行一遍,获取的都是"用户名" if(username_value=="用户名"){ $(this).val(""); } }); $("#username").blur(function(){ var account_value=$(this).val(); if(account_value==""){ $(this).val("用户名"); } }); }); </script>--> <script> function txtfocus(text) { if(text.value=="用户名"|| text.value=="密码") text.value=""; } function userblur(text) { if(text.value=="") text.value="用户名"; } function pwdblur(text) { if(text.value=="") text.value="密码"; } </script> </head> <body> 账号:<input id="username" type="text" value="用户名" onfocus="txtfocus(this)" onblur="userblur(this)" /> 密码:<input id="pwd" type="text" value="密码" onfocus="txtfocus(this)" onblur="pwdblur(this)" /> </body> </html>