首頁  >  文章  >  web前端  >  jquery為什麼寫入口函數

jquery為什麼寫入口函數

(*-*)浩
(*-*)浩原創
2019-05-30 11:43:433009瀏覽

入口函數的作用,等待頁面載入完畢,有一個獨立的作用域,

jquery為什麼寫入口函數

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中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn