<head lang="en">
<meta charset="UTF-8">
<title>搜索框特效</title>
<style type="text/css">
* {
margin: 0px;
padding: 0px;
font-size: 12px;
}
input {
float: left;
}
#searchtxt {
width: 222px;
height: 38px;
line-height: 38px;
padding-left: 30px;
border: none;
background: url(images/bg.jpg) no-repeat;
}
.search_btn {
width: 90px;
height: 38px;
line-height: 38px;
border: none;
background: url(images/btn.jpg) no-repeat;
margin-left: -4px;
cursor: pointer;
}
</style>
<script type="text/javascript" src="js/html" title=jquery>jquery-1.12.4.js"></script>
<script>
$(function() {
//获取搜索框,绑定获取焦点事件
$("#searchtxt").focus(function() { //获取焦点事件
//1.获取搜索框的值
var txt_value = $(this).val();
//2.如果搜索的值等于电风扇,清空value属性值
if(txt_value == "电风扇") {
$(this).val("");
}
});
//获取搜索框,绑定失去焦点事件
$("#searchtxt").blur(function() {
//1.获取搜索框的值
var txt_value = $(this).val();
//2.如果搜索框的值为空,显示电风扇
if(txt_value == "") {
$(this).val("电风扇");
}
})
})
</script>
</head>
<body>
<input name="" type="text" class="search_txt" value="电风扇" id="searchtxt" />
<input type="button" class="search_btn" />
</body>