效果图
代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>58同城搜索框</title>
<style>
input{
width: 380px;
height: 50px;
font-size: 24px;
border: 1px solid red;
outline: none;
color: #999;
padding: 0px;
padding-left: 30px;
vertical-align:middle;
border-radius: 10px 0px 0px 10px;
}
.reach{
color: #fff;
width: 60px;
height: 52px;
background-color: red;
padding: 0;
margin-left: -10px;
cursor: pointer;
border-radius: 0px 10px 10px 0px;
}
div{
width: 500px;
height: 60px;
margin: 50px auto;
}
</style>
<script src="../jQuery.js"></script>
</head>
<body>
<div>
<input type="text" value="找工作上58">
<input class="reach" type="submit" value="搜索">
</div>
<script>
function yuanshengjs() {
var input = document.getElementsByTagName('input')[0];
input.onfocus = function() {
if(this.value == "找工作上58"){
this.value = "";
this.style.color = "#000";
}
}
input.onblur = function() {
if(this.value == ""){
this.value = "找工作上58";
this.style.color = "#999";
}
}
}
$("input:first").focus(function(){
if($(this).val() == "找工作上58"){
$(this).val("");
$(this).css("color","#000");
}
})
$("input:first").blur(function(){
if($(this).val() == ""){
$(this).val("找工作上58").css("color","#999");
}
})
</script>
</body>
</html>