仿淘宝搜索框

Posted 寻觅聪

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了仿淘宝搜索框相关的知识,希望对你有一定的参考价值。

<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>

以上是关于仿淘宝搜索框的主要内容,如果未能解决你的问题,请参考以下文章

仿淘宝搜索框(点击隐藏文字)

仿淘宝页面的搜索引擎,点击输入框文字不消失

仿京东搜索框实例

js仿百度搜索框

仿京东手机端搜索框

仿百度搜索提示框效果