首页 > 代码库 > 仿淘宝搜索框

仿淘宝搜索框

<style type="text/css">
#search{
margin: 100px auto;
width: 300px;
height: 40px;
position: relative;
}
#search input{
width: 200px;
height: 20px;
}
#search label{
position: absolute;
left: 20px;
top: 5px;
cursor: text;
color: #ccc;
}
</style>
<script type="text/javascript">
window.onload = function(){
var txt = document.getElementById("txt");
var message = document.getElementById("message");
txt.oninput = onpropertychange = function(){
if(txt.value =http://www.mamicode.com/=""){
message.style.display = "block";
}else{
message.style.display = "none";
}
}
}

</script>

<body>
<div id="search">
<input type="text" id="txt">
<label for="txt" id="message">好睡眠好床品</label>
</div>
</body>

仿淘宝搜索框