因为加载内容比较慢,所以用户可能在li上不经意点击了两次,那么就会请求两次,这是我们不想看到的。
今天在javascript-jquery群上一筒子发了两个demo给我,他的方法是先将单击的li节点拷贝出来,在加载完后
在重新插回去,显然不太适合我做的功能。
正一筹莫展,想了一下,何不在li点击时加入loading图片(在ajax加载前),判断li节点上是否存在了img元素,
没有则加载ajax内容,否则不处理。
测试了可以通过,(^o^)/。
复制代码 代码如下:
jquery ajax加载绑定事件
); //加载图片
$.get(table.html,function(data){
$current.append(data).children(span).addclass(highlight).find(img).remove(); //加载完成移除加载图片
});
}
}else{
if($current.children(table).is(:visible))
{
$current.children(span).removeclass(highlight).next(table).hide();
}else{
$current.children(span).addclass(highlight).next(table).show();
}
}
});
});
}
});
demo©copyright by tomi-eric's
课程
演示地址 http://demo.jb51.net/js/jquery_li_click/demo.html
打包下载 http://xiazai.jb51.net/201012/yuanma/jquery_li_click.rar