代码如下:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-CN"><head> <title>Document</title> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /></head><body> <div> <ul> <li>春</li> <li>夏</li> <li>秋</li> <li>冬</li> </ul> <script type="text/javascript"> var list = document.getElementsByTagName('li'); var len = list.length; for (var i = 0; i < len; i++) { list[i].onclick = function () { alert(i); } } </script> </div></body></html>想要的效果,分别点击春夏秋冬,弹出0,1,2,3,为什么实际结果都是弹出4。应该如何修改?
添加回答
举报
0/150
提交
取消