Front-end series of tutorials to tell to the programmer to see (55) - jQuery entry function


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)

Thinking out of the woods, set foot on the road --Android develop sophisticated Advanced essence record

Android programmers looking to tell the front tutorial series (40 episodes free video tutorials + source code)


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.

发布了1022 篇原创文章 · 获赞 1986 · 访问量 238万+

Guess you like

Origin blog.csdn.net/lfdfhl/article/details/102657475