入口函数的作用,等待页面加载完毕,有一个独立的作用域,
jQuery入口函数的编写方式如下
<script> // 方式一 $(document).ready(function () { alert("hello lnj"); }); // 方式二,最常使用的一种 $(function () { alert("hello lnj"); }); // 方式三 jQuery(document).ready(function () { alert("hello lnj"); }); // 方式四 jQuery(function () { alert("hello lnj"); }); </script>
实例:
<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>
以上就是jquery为什么写入口函数的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号