关于加载数据后,按钮禁用问题。
$(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>")
});
});
});
})是不是写在里头根本没反应的