使用for of 循环操作元素: 点击哪个li 哪个li 变成红色 <ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> </ul> <script> // 点击哪个li 哪个li 变成红色 let lis = document.querySelectorAll('li'); for (let val of lis) { val.addEventListener('click', function() { val.innerText = +val.innerText + 1 val.style.backgroundColor = 'red' }) }; </script> 点击哪个li 哪个li 变成 蓝色 <ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> </ul> <script> // 点击哪个li 哪个li 变成 蓝色 let lis = document.querySelectorAll('li'); for (let vals of lis) { vals.addEventListener('click', function() { vals.style.backgroundColor = 'blue' }) }; </script>