我有一个加载函数,希望代码在加载时将一些html写入div,当它完成时,显示页面.我在ajaxStart和ajaxComplete事件上看到一些小写,但我不知道如何实现它们.
这是我正在考虑使用的jquery,但是不知道如何在我目前的代码中实现…
$(document).ajaxStart(function(){ $('#content').html("Loading Content..."); });
这是我目前使用的jquery:
//Load content $(".load").click(function(){ $("#content").empty(); loadName = $(this).attr("id"); $("#content").load("/content/" + loadName + ".PHP"); });
@R_403_323@
如果它是一个div,并且您想使用加载消息/指示器更新其内容,则可以这样做:
$("#content").html('<strong>Loading...</strong>') .load("/content/" + loadName + ".PHP");
我不会使用ajaxStart和ajaxStop / ajaxComplete global events,除非您有所有ajax调用的常用加载指示符.也就是说,可以做到如下:
$("#loading").bind("ajaxStart",function(){ $(this).show(); }).bind("ajaxStop",function(){ $(this).hide(); });