2023-08-18T15:55:46.png

<!DOCTYPE html>
<html lang="zh">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>

  <style>






  </style>

</head>
<body>
  
  

<ul id="list">

<li>列表1</li>
<li>列表2</li>
<li>列表3</li>
<li>列表4</li>
<p>一个文本</p>
</ul>







<script>


//点击列表获取所点击的列表文本并输出到控制台
var list = document.getElementById("list");

list.addEventListener("click",function(){

if(event.target.tagName.toLowerCase() === "li"){

console.log(event.target.innerHTML);

};

});




</script>






</body>
</html>