排他思想:
<!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>
ul,
li {
list-style-type: none;
}
.active {
color: pink;
}
</style>
</head>
<body>
<ul class="myul">
<li class="active">111</li>
<li>222</li>
<li>333</li>
<li>444</li>
</ul>
<div>
<div>change111</div>
<div>change222</div>
<div>change333</div>
<div>change444</div>
</div>
<script>
let onediv = document.querySelector('div');
let allli = document.querySelectorAll('li');
let alldiv = onediv.querySelectorAll('div');
allli.forEach((item, index) => {
allli[index].index = index;
item.addEventListener('click', function () {
for (let i = 0; i < allli.length; i++) {
allli[i].className = '';
alldiv[i].style.display = 'none';
};
this.className = 'active';
alldiv[index].style.display = 'block';
})
});
</script>
</body>
</html>