far*_*oft 5 javascript jquery dom document-ready ready
在主体中加载脚本js文件后调用$(document).ready()吗?
如果我在脚本元素的头部放置$(document).ready(),它采用一个回调函数,该函数使用在文件中声明的函数,其脚本元素在主体中加载如下:
<!DOCTYPE HTML>
<html>
<script src="jquery.js" type="text/javascript"></script>
<script>
$(function(){
hello();
})
</script>
<head>
</head>
<body>
<script src="http://somewhere/helloFuncDeclaration.js" type="text/javascript"></script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
这是一种正确的方法,并保证在调用函数hello()之前将加载helloFuncDeclaration.js?
可以肯定的是,使用窗口 onload 处理程序:
$(window).on('load', hello);
Run Code Online (Sandbox Code Playgroud)
或者像这样使用它:
<script onload="hello()" src="http://somewhere/helloFuncDeclaration.js" type="text/javascript"></script>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14954 次 |
| 最近记录: |