关于加载数据后,按钮禁用问题。

来源:1-2 使用getJSON()方法异步加载JSON格式数据

淡水狗

2017-08-03 19:54

           $(function(){
               $("#btnShow").bind("click",function(){
                 $.getJSON("http://www.imooc.com/data/sport.json",function(data){
                    $.each(data,function(index,sport){
                        $(this).attr('disabled' , 'true'); //按钮禁用
                        if(index == 2)
                        $("ul").append("<li>" + sport["name"] + "</li>")
    
                    });
                 });
               });
           })

老师是   $(this).attr('disabled' , 'true');  写在回调函数里头 ,但点击后并没有禁用。  反而直接写在外头的时候有效果。如下面

    $(function(){
               $("#btnShow").bind("click",function(){
                 $(this).attr('disabled' , 'true'); //按钮禁用
                 $.getJSON("http://www.imooc.com/data/sport.json",function(data){
                    $.each(data,function(index,sport){
                        if(index == 2)
                        $("ul").append("<li>" + sport["name"] + "</li>")
    
                    });
                 });
               });
           })

是不是写在里头根本没反应的

写回答 关注

1回答

  • 淡水狗
    2017-08-03 19:57:54

    好吧 我明白了 没赋予一个变量名。 

jQuery基础(五)一Ajax应用与常用插件

如何用jquery实现ajax应用,加入学习,有效提高前端开发速度

69095 学习 · 400 问题

查看课程

相似问题