The role of the entry function, waiting for the page to be loaded, has an independent scope,
jQuery entry function The writing method is as follows
<script> // 方式一 $(document).ready(function () { alert("hello lnj"); }); // 方式二,最常使用的一种 $(function () { alert("hello lnj"); }); // 方式三 jQuery(document).ready(function () { alert("hello lnj"); }); // 方式四 jQuery(function () { alert("hello lnj"); }); </script>
Example:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <script src="jquery-1.7.1.js" type="text/javascript"></script> </head> <body style=" overflow-y:scroll;overflow-x:auto;"> <input type="text" id="dd1" value="" /> <textarea id="tt" cols="30" rows="30"></textarea> </body> <script> var i=1; //jQuery方式 $(function(){ var str=$("#tt").val()+'\r\n'+'$_B加载完毕'+i; $("#tt").val(str); i++; }) ; </html>
The above is the detailed content of Why does jquery write entry functions?. For more information, please follow other related articles on the PHP Chinese website!