猿问

var $this=$(this);为什么这样就不等价了。

 $("#btnShow").bind("click", function () {

                   

                    $.getJSON("http://www.imooc.com/data/sport.json",function(data){

                        $(this).attr("disabled", "true");  //这行代码,为什么运行不了,如果先声明var $this=$(this)  用$this就可运行。

                        $.each(data, function (index, sport)                   {

                            

                            $("ul").append("<li>" + sport["name"] + "</li>");

                        });

    

                    });

                })


平行时空0
浏览 1160回答 2
2回答

Caballarii

因为你这里的this已经不是$("#btnShow")这个按钮了,而是$.getJSON("http://www.imooc.com/data/sport.json",function(data){这里的某个对象,具体哪个不清楚,而你之前用一个变量把$(this)存起来的话,再调用这个对象就还是这个按钮。
随时随地看视频慕课网APP

相关分类

JQuery
我要回答