<li>0000000</li>
<li>11111111</li>
<li>22222222</li>
<li>33333333</li>
script type="text/javascript">
var aLi = document.getElementsByTagName("li");
// for(var i = 0 ; i < aLi.length;i++)
// {
// aLi[i].index = i;
// aLi[i].onclick = function()
// {
// alert(this.index);
// }
// }
//闭包
// for(var i = 0 ; i < aLi.length;i++)
// {
// (function(i){
// aLi[i].onclick = function(){
// alert(i);
// }
// })(i)//函数自调用 接受自调用传进来的参数
// }
function person(){
this.name = "ketty";
var that = this;
console.log(this);
return {
getName:function(){
alert(that.name);
},
setName:function(newName){
that.name = "hello";
}
}
}
var b = new person();//新建对象实例
var c = new person();
b.setName("hello");
b.getName();
c.getName();
</script>