发表于: 2017-03-09 02:11:34
1 1115
今日完成:
1 任务4:完成了点击玩家设定状态的功能,kDead-被杀死;vDead-被投死。
自执行函数:用()将函数定义包裹,就成为函数表达式,也就是自执行函数,解决的是循环闭包的问题。使循环变量可以传递到内部函数。
for(i=0;i<gamerAmount;i++){
(function (i) {
$(gamerDom[i]).on("click",function(){
console.log(i);
console.log(gamerObj);
console.log(gamerObj[i].identity);
console.log(gamerObj[i].state);
if(gamerObj[i].identity=="平民"){
if(gamerObj[i].state=="alive"){
if(localStorage.pageType=="killerPage"){gamerObj[i].state="kDead";}
else{gamerObj[i].state="vDead";}
// localStorage.gamerObjStorage=JSON.stringify(gamerObj);
$(gamerDom[i]).css({"border":"0.05rem solid #f00"});
}
else{
gamerObj[i].state="alive";
// localStorage.gamerObjStorage=JSON.stringify(gamerObj);
$(gamerDom[i]).css({"border":"0.05rem solid #fff"});
}
}
else {}
})
})(i)
}
2知识点:
.css()方法:由于选中属性名或用于设定属性值
选中:.css("属性名")
设定属性值:.css({"名":"值","名":"值"})
.on()方法:搬运自jq源码
jQuery.fn.extend( {
on: function( types, selector, data, fn ) {
return on( this, types, selector, data, fn );
},
one: function( types, selector, data, fn ) {
return on( this, types, selector, data, fn, 1 );
},
off: function( types, selector, fn ) {
var handleObj, type;
if ( types && types.preventDefault && types.handleObj ) {
明日计划:
1 继续任务4的任务,解决问题
2 学习ns图,把任务4的ns图画出来。
问题:很多原理不懂,然而还是喜欢按自己方法做。收获:任务4的新进展。
评论