Complete C language self-study manual (33)
Android multi-resolution framework for adaptation
JavaWeb core technology tutorial series
HTML5 front-end development combat tutorial series
MySQL database gymnastics tutorials (35 graphical version)
And overthrow their own past - Custom View tutorial series (10)
Copyright Notice
- This article original author: Columbia Valley's younger brother
- On the blog address: http: //blog.csdn.net/lfdfhl
Entry function
Learning the JavaScript event when the page before we explain the JavaScript event handlers such as window.onload indicate when the page finished loading after trigger. Examples are as follows:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>JavaScript onload</title>
<script type="text/javascript">
window.onload=function(){
alert("当页面加载完毕时执行该函数")
}
</script>
</head>
<body>
<h2 id="author" style="color: red;">本文作者:谷哥的小弟</h2>
<h2 id="blog" style="color: red;">博客地址:http://blog.csdn.net/lfdfhl</h2>
</body>
</html>
In jQuery also provides a similar function, we often referred to as the entry function. Here, let's learn commonly written entry function.
Common written entry function
method one
The syntax is as follows:
$(document).ready(function() {
});
Examples are as follows:
$(document).ready(function() {
alert("page load finish");
});
Second way
The syntax is as follows:
$().ready(function() {
});
Examples are as follows:
$().ready(function() {
alert("page load finish");
});
Three ways
The syntax is as follows:
$(function() {
});
Examples are as follows:
$(function() {
alert("page load finish");
});
In the actual development, the code is easy to write the usual way.
The difference between the entry point and window.load
jQuery entry function and native JavaScript window.onload similar functions, but there are differences; summarized as follows:
-
Different loading modes
JavaScript Native Interface window.onload need to wait until all (for example: text, pictures, etc.) loaded will be performed. i.e. loaded jQuery entry function is executed on the basis of the interface (excluding images and other resources). -
Loads of different
JavaScript native window.onload called only once on the same page. In other words: While it is possible to write multiple window.onload on the page, but only the last valid, before the onload will be overwritten. The difference is, you can write multiple times on the same page and the effective implementation of jQuery entry function.