e.target+addEventListener事件委托

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>事件委托</title>
<style>ul li {
cursor: pointer;
}</style>
</head>

<body>
<ul>
<li>知否知否,点我应有弹框在手!</li>
<li>知否知否,点我应有弹框在手!</li>
<li>知否知否,点我应有弹框在手!</li>
<li>知否知否,点我应有弹框在手!</li>
<li>知否知否,点我应有弹框在手!</li>
</ul>
<script>// 事件委托的核心原理:给父节点添加侦听器, 利用事件冒泡影响每一个子节点

var ul = document.querySelector('ul');


ul.addEventListener('click', function (e) {
// alert('知否知否,点我应有弹框在手!');
// e.target 这个可以得到我们点击的对象
e.target.style.backgroundColor = 'red'


})



/* */
/* var lis = document.querySelectorAll('li'); */
/* for (var i = 0; i < lis.length; i++) { */
/*
/* lis[i].onclick = function () { */
/* for (var i = 0; i < lis.length; i++) { */
/* lis[i].className = ' '; */
/* } */
/* this.className = 'current'; */
/* } */
/* } */
/* */
/* */</script>
</body>

</html>