jquery ajax加载绑定事件 <script> <BR>$(function(){ <BR>setHeight("#siderbar",130); // 设置侧边栏的高度 <BR>$(window).resize(function(){setHeight("#siderbar",130)}); //窗口变化时重新设置侧边栏高度 <BR>$.get("sider.html",function(data){ <BR>$('#siderbar_box').append(data); <BR>}); <BR>/*设置ID的高度*/ <BR>function setHeight(id,h){ <BR>var windowHeight=$(window).height(); <BR>$(id).css({"height":(windowHeight-h)+"px"}); <BR>} <BR>// 绑定加载后的li的查看 <BR>$("#siderbar_box ul li a").live("click",function(){ <BR>var $current=$(this); <BR>var $currentli=$(this).parent(); <BR>if($currentli.children("ul").attr("id")==undefined) //第一次需ajax加载 <BR>{ <BR>$currentli.siblings().children("ul").slideUp('fast'); <BR>$currentli.siblings().children("a").removeClass("focus"); <BR>$.get("chapter.html",function(data){ <BR>$current.addClass("focus").parent().append(data); <BR>showChapter(); //在content去显示主要内容 <BR>}); <br><br>}else{ <BR>$currentli.siblings().children("ul").slideUp('fast'); <BR>$currentli.siblings().children("a").removeClass("focus"); <BR>if($currentli.children("ul").is(":visible")) //处于展开状态 <BR>{ <br><br>$current.removeClass("focus").parent().children("ul").slideUp('fast'); <BR>}else{ <br><br>$current.addClass("focus").parent().children("ul").slideDown('slow'); <BR>showChapter(); <BR>} <BR>} <BR>}); <BR>//content显示列表标题 <BR>function showChapter(){ <BR>$.get("chapter.html",function(data){ <BR>$("#content").html(data); <BR>$("#content ul li").live("click",function(){ //绑定加载后的标题单击事件 <BR>$current=$(this); <BR>if($current.children("table").attr("id")==undefined) //单击标题,第一次ajax加载 <BR>{ <BR>if($current.children("span").find("img").size()<1) //只加载一次内容,防止多次请求加载 <BR>{ <BR>$current.children("span").append("<img src='loading.gif' border='none'/ alt="jquery 单击li防止重复加载的实现代码_jquery" >"); //加载图片 <BR>$.get("table.html",function(data){ <BR>$current.append(data).children("span").addClass("highlight").find("img").remove(); //加载完成移除加载图片 <BR>}); <BR>} <BR>}else{ <br><br>if($current.children("table").is(":visible")) <BR>{ <BR>$current.children("span").removeClass("highlight").next("table").hide(); <br><br>}else{ <br><br>$current.children("span").addClass("highlight").next("table").show(); <BR>} <BR>} <br><br>}); <BR>}); <BR>} <BR>}); <BR></script>