1、制作简易选项卡(只制作开头)
目标:点击“正在播出”css样式就到了它身上,而“即将上映”没有样式;同样当点击“即将上映”样式就转换到它这里来了
重点思路:给两个标签都绑上点击事件,先将class选择器选择的属性写好,然后通过classList给标签增加这个类名或者移除这个类名来控制。
具体的代码思路是:先写好class选择器样式:见“.active{}”,然后第一个li标签点击事件要执行的代码是:当点击“正在播出”,它增加“active”这个类名,赋予属性,然后移除另一个item2的“active”属性;当点击item2时,给item2增加“active”属性,删除item1的“active”属性。
核心代码:画红圈的那个
完整代码:
<!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>Document</title>
<style>
*{
margin: 0%;
padding: 0%;
}
ul{
list-style: none;
display: flex;
}
li{
height: 50px;
line-height: 50px;
text-align: center;
flex: 1;
}
.active{
color: red;
border-bottom: 1px solid red;
}
</style>
</head>
<body>
<ul>
<li class="active" id="item1">正在播出</li>