jquery中通过ajaxstart()和ajaxstop()两个方法提供了类似的功能。当一个ajax请求启动时,并且没有其他未完成的ajax请求时,将调用ajaxstart()方法。同样,ajaxstop()方法则是在所有ajax请求都完成时调用。这些方法的参数都是一个函数,这个函数将在事件发生时被调用。
例子
. 代码如下:
<html xmlns="https://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script src="jquery-1.4.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#button1").click(function(){
$.post("default2.x","",function(data){
$("#x").text(data);
},"text");
});
$("#my").ajaxstart(function(){
$(this).show();
}).ajaxstop(function(){
$(this).hide();
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<input id="button1" type="button" value="button" />
<p id="my" style=" display:none">
<img src="loading.gif" />
</p>
<p id="x"></p>
</form>
</body>
</html>
如对本文有疑问, 点击进行留言回复!!
[JSOI2008]Blue Mary的战役地图 Hash题解
牛客编程巅峰赛S1第8场 - 青铜&白银 A.数学B.贪心C.枚举
网友评论