我在没有 JavaScript 框架的情况下工作,但我想在加载 DOM 时调用一个函数。
我不能/不想使用属性 onload
关于<body>
标签。
最佳答案
我认为http://code.google.com/p/domready/这正是您正在寻找的。p>
If you are ever writing your own JavaScript file that cannot depend on the existing libraries out there and would like to execute only after the page is loaded, this library is for you.
Simply do this:
<html lang="en">
<head>
<script src="domready.js" type="application/javascript"></script>
<script type="application/javascript">
DomReady.ready(function() {
alert('dom is ready');
});
</script>
</head>
<body>
</body>
</html>
关于javascript - Dom加载事件跨浏览器原生javascript代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24974491/