如何挂载DOM加载的事件? [英] How to hook the DOM loaded event?
本文介绍了如何挂载DOM加载的事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
基本上,我想在dom加载时显示一个加载器(我不是指Ajax请求 - 用户第一次访问页面)?
感谢所有提前
解决方案
所有流行的JavaScript库有一个DOM加载事件可以用于此。
基本上:
< HTML>
< head>
< script>
//如果使用jQuery
$(document).ready(function(){$('#load')。hide();});
//如果使用Prototype
document.observe(dom:loaded,function(){$('loading')。hide();});
< / script>
< / head>
< body>
< div id =loading> Loading ...< / div>
<! - 其余页面 - >
< / body>
< / html>
Can someone point me in the direction to hook the DOM loaded event?
Basically, i want to display a loader while the dom is loading (I dont mean Ajax requests- the first time a user hits a page) ?
Thanks all in advance
解决方案
All of the popular Javascript libraries have a "DOM loaded" event you can use for this.
Essentially:
<html>
<head>
<script>
// if using jQuery
$(document).ready(function() { $('#loading').hide(); });
// if using Prototype
document.observe("dom:loaded", function() { $('loading').hide(); });
</script>
</head>
<body>
<div id="loading">Loading...</div>
<!-- rest of page -->
</body>
</html>
这篇关于如何挂载DOM加载的事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文