jquery为什么写入口函数


本文摘自PHP中文网,作者(*-*)浩,侵删。

入口函数的作用,等待页面加载完毕,有一个独立的作用域,

jQuery入口函数的编写方式如下

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

<script>

        // 方式一

        $(document).ready(function () {

            alert("hello lnj");

        });        // 方式二,最常使用的一种

        $(function () {

            alert("hello lnj");

        });        // 方式三

        jQuery(document).ready(function () {

            alert("hello lnj");

        });        // 方式四

        jQuery(function () {

            alert("hello lnj");

        });

</script>

实例:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

<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为什么写入口函数的详细内容,更多文章请关注木庄网络博客

相关阅读 >>

jQuery怎么遍历数组

jQuery中怎样实现两秒之后刷新页面

如何解决jQuery $.post 乱码问题

jQuery如何使用新元素来替换所选元素

jQuery如何判断元素是否存在

jQuery怎么增加css属性

jQuery对象与dom对象的区别有哪些?

jQuery中图片加载失败怎么办

jQuery中能用session吗

jQuery怎样创建元素节点

更多相关阅读请进入《jQuery》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...