Created
September 12, 2016 09:28
-
-
Save itboos/2c0cf87b8c342bddd7889b8beeaf4417 to your computer and use it in GitHub Desktop.
点击Li实现循环弹出自己的索引
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en" ng-app="myTest"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |
<title>今天是9月12号,a new day!</title> | |
<style type="text/css"> | |
#ul1 li{ | |
list-style-type: none; | |
width:200px; | |
height:30px; | |
background:#ccc; | |
margin-bottom: 10px; | |
cursor: pointer; | |
} | |
</style> | |
<script type="text/javascript"> | |
window.onload=function(){ | |
var aLis=document.getElementById("ul1").getElementsByTagName("li"); | |
console.log(aLis); | |
for(var i=0;i<aLis.length;i++){ | |
(function(n){ | |
aLis[i].onclick=function(){ | |
alert(n); | |
} | |
})(i); | |
} | |
} | |
</script> | |
</head> | |
<body> | |
<ul id="ul1"> | |
<li>这是第1个LI</li> | |
<li>这是第2个LI</li> | |
<li>这是第3个LI</li> | |
<li>这是第4个LI</li> | |
<li>这是第5个LI</li> | |
</ul> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
闭包二三事配例子