码迷,mamicode.com
首页 > 其他好文 > 详细

闭包 (循环事件获取不到i)

时间:2015-02-13 16:19:13      阅读:83      评论:0      收藏:0      [点我收藏+]

标签:

for(var i in fav){

(function(){
                var p=i;
                var obj=$S.getId(fav[i]);
                $S.addHandler($S.getId(fav[i]),‘click‘,function(){
                        $S.jsonp({url:‘http://www97.xcar.com.cn/bbs/api/api.php?action=fav_forum&fid=‘+p,callback:function(data){
                                  if(data.error==0){
                                     //成功收藏
                                     $S.getId(‘S_right‘).style.display = "block";
                                     setTimeout("$S.getId(‘S_right‘).style.display =‘none‘;",3000);
                                      obj.className += " "+‘S_active‘;
                                 }else if(dta.error==1){
                                     //未登陆
                                 }else if(data.error==3){
                                     //超过20条
                                     $S.getId(‘S_wrong‘).style.display = "block";
                                     setTimeout("$S.getId(‘S_wrong‘).style.display =‘none‘;",3000);
                                }
                        }});
                });
            })();

}

闭包 (循环事件获取不到i)

标签:

原文地址:http://www.cnblogs.com/afei-happy/p/4290249.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!