jQuery学习笔记(9)--jquery中的事件--$(document).ready()

1.$(document).ready()方法是事件模块中最重要的一个函数,可以极大地提高web应用程序的相应速度。

2.执行时机:DOM就绪后就会执行,而javascript中window.onload方法是在网页中的所有元素(包括元素的所有关联文件)完全加载到浏览器后才执行。

3.可多次使用。

4.有简写的形式:$(function){}

window.onload与$(document).ready()的比较:

 

 1  <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
 2     <script type="text/javascript">
 3 
 4 
 5         $(document).ready(function () {
 6                        one();                     
 7 
 8         });
 9 
10         //简写形式1
11         $().ready(function () {
12             two();
13 
14         });
15 
16         //简写形式2
17         $(function () {
18             three();
19         });
20 
21         function one() {
22             alert("1");
23 
24         }
25 
26         function two() {
27             alert("2");
28 
29         }
30 
31         function three() {
32             alert("3");
33 
34         }
35     </script>
View Code
原文地址:https://www.cnblogs.com/hshuai/p/4300537.html