Home  >  Article  >  Web Front-end  >  Why does jquery write entry functions?

Why does jquery write entry functions?

(*-*)浩
(*-*)浩Original
2019-05-30 11:43:433012browse

The role of the entry function, waiting for the page to be loaded, has an independent scope,

Why does jquery write entry functions?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn