仿淘宝搜索框

<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 == ""){
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>

posted @ 2017-05-13 09:38  寻觅聪  阅读(162)  评论(0编辑  收藏  举报