用jquery实现输入框消失文字

<html>
<head>
<title>用jquery实现输入框消失文字</title>
<style type="text/css">
.default {
font-weight: bold;
color: #787878;
}
</style>
<script type="text/javascript" src="/js/jquery/jquery-1.8.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#keywords").focus(function () {
var $this = $(this);
if ($this.val() == $this[0].defaultValue) {
$this.css("color","#0cf").val("");
}
}).blur(function () {
var $this = $(this);
if ($this.val() == "") {
$this.removeAttr("style").val($this[0].defaultValue);
}
})//keywords
});
</script>
</head>
<body>
<div id="content">
<form method="POST" id="user" action="">
User Name:<input type="text" id="keywords" class="default" name="keywords" value="Enter your name"/><br/>
PassWord:<input type="text" id="password" class="default" name="password" value="Enter your password"/>
<input type="submit" name="sub" value="login"/>
</form>
</div>
</body>
</html>


[img]http://dl.iteye.com/upload/attachment/0083/8218/d6f3e157-330d-33be-9245-4e354e1d18e9.jpg[/img]

[img]http://dl.iteye.com/upload/attachment/0083/8220/9fc580f5-aa0b-3e2a-9f9c-4620591e5d98.jpg[/img]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值