创建一个加载Div
我正在尝试创建一个愚蠢的加载 div。我只是想让它在每次单击按钮时显示。我有一个名为 ajaz-loader.gif 的 gif,位于 img/
我有这个,但它不起作用...我刚刚在互联网上找到它。有什么想法吗?
<script>
$('#loadingDiv').ajaxStart(function() {
$(this).show();
}).ajaxComplete(function() {
$(this).hide();
});
</script>
I am trying to create a stupid loading div. I just want it to show everytime a button is clicked. I have a gif named ajaz-loader.gif located in img/
I have this and it doesn't work... I just found it on the internet. Any ideas?
<script>
$('#loadingDiv').ajaxStart(function() {
$(this).show();
}).ajaxComplete(function() {
$(this).hide();
});
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
确保将您的代码包装在 a 中
然后如果它仍然不起作用,请仔细检查您的 #loadingDiv 是否
看起来像这样:)
Web服务运行时显示加载
Make sure to wrap your code inside a
Then if it still doesn't work, double check if your #loadingDiv
That looks like this :)
Display loading while webservice is running
这将在 Ajax 调用之前显示您的加载 div,然后在成功与否后隐藏它。
This will show your loading div before the Ajax call then hide it after weather its successful or not.
您可能想发布更多代码。根据您上面的情况,尚不清楚问题可能是什么。也许事情很简单,例如您没有正确加载 jQuery 或者为元素指定的 ID 不正确。也许它有点复杂,例如触发 ajaxStart 的事件永远不会触发。
需要注意的是,下面的代码中有一些次优的做法(例如,将样式信息直接放入 HTML 中),并且我没有处理 ajax 或成功后隐藏,这可能会让您开始:
这可能会让您进入正确的方向。我怀疑这还不足以完成您想做的所有事情,但如果您真正想要的是“只是...每次单击按钮时都显示”,那么,它就做到了这么多,并且针对 jQuery 修改它可能并不困难...
You might want to post more code. With what you have above, it's unclear what the problem might be. Perhaps it's something simple, such as you're not loading jQuery properly or the ID speicified for the element is incorrect. Perhaps it's somewhat more involved, such as the event that triggers ajaxStart never fires.
With the caveat that there are some suboptimal practices in the code below (e.g., putting style information directly in the HTML) and that I'm not handling ajax or hiding after success, this should might you started:
That might get you going in the right direction. I suspect it's not enough to do everything you want to do, but if all you really want is "to just...show everytime a button is clicked", well, it does that much, and modifying it for jQuery is likely not difficult...
我制作了自己的加载伪类,并且在大型 Web (jsp) 应用程序中运行良好。
我的代码是这样的:
当我运行 ajax 时调用
CMSLoading.start()
,当 ajax 完成或死亡时调用CMSLoading.stop();
I made my own loading pseudo-class and works fine in big web (jsp) application.
My Code is something like this:
When I run an ajax call
CMSLoading.start()
and when ajax finish or die callCMSLoading.stop();