闭包的应用
<!DOCTYPE HTML> <HTML> <HEAD> <TITLE></TITLE> <META charset="utf-8"> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> <style> ul{ list-style:none; font-size:25px;} </style> </HEAD> <BODY> <div class="nav"> <ul> <li>春</li> <li>夏</li> <li>秋</li> <li>冬</li> </ul> </div> <script type="text/javascript"> window.onload=function(){ var lis=document.getElementsByTagName('li'), len=lis.length; for(var i=0;i<len;i++){ lis[i].onclick=(function(m){ return function(){ alert(m+1);//点春夏秋冬依次输出1、2、3、4 } })(i); } } </script> </BODY> </HTML>