console
var lis = document.getElementsByTagName('li');
for(var i = 0;i < lis.length;i++) {
lis[i].onclick = function () {
for(var j = 0;j < lis.length;j++) {
lis[j].className ='';
}
this.className = 'active';
}
}
var txt = document.getElementById('txt');
var lab = document.getElementById('lab');
txt.oninput = function () {
if(this.value == '') {
lab.style.display = 'block';
}
else {
lab.style.display = 'none';
}
}
<div class="wrapper">
<ul>
<li class="active"><a href="#">宝贝</a></li>
<li><a href="#">天猫</a></li>
<li><a href="#">店铺</a></li>
</ul>
<div class="search">
<input type="text" id="txt">
<label for = "txt" id="lab">请输入要购买的商品</label>
</div>
</div>
*{
padding: 0;
margin: 0;
}
.wrapper {
width: 800px;
margin: 30px auto;
}
ul {
list-style: none;
overflow: hidden;
}
ul li {
float: left;
width: 150px;
height: 50px;
line-height: 50px;
text-align: center;
background-color: #fff;
}
li a {
color: red;
text-decoration: none;
}
li.active {
background-color: red;
}
li.active a {
color: white;
}
.search {
margin: 20px 0;
position: relative;
}
#txt {
display: block;
outline: none;
width: 447px;
height: 50px;
position: absolute;
border: 2px solid orange;
border-radius: 10px;
}
#lab {
display: block;
position: absolute;
top: 15px;
lest: 30px;
font-size: 20px;
color: rgba(0,0,0,0.5);
}