Home > Web Front-end > JS Tutorial > The role of $(function()) in jQuery

The role of $(function()) in jQuery

angryTom
Release: 2020-04-03 18:08:45
forward
7243 people have browsed it

This article introduces the role of $(function()) in jQuery, which has certain reference value. I hope it will be helpful to friends who are learning jQuery and JavaScript!

The role of $(function()) in jQuery

The role of $(function()) in jQuery

$(function()) is equivalent to $(document). ready(function()), the meaning is very simple, it means to wait until the page is loaded before starting to execute the function.

Before using $(function()), my $("body").click() operation did not work. I executed the function first. At this time, the DOM has not been loaded, so it does not work. Take effect. After putting the js function into $(function()), it can run normally.

The role of $(function()) in jQuery

$(function(){//五分钟无操作,返回系统首页,timeToreturn.js
    function timeToReturn(){
        window.location.href = "http://localhost:8080/zhongCourt/";
    }
    var nowtime = Date.parse(new Date());
    var timeend = Date.parse(new Date());
 
    $("body").click(function(){
        nowtime = Date.parse(new Date());
        console.log("nowtime" + nowtime);   
    });
 
    function check(){
        timeend = Date.parse(new Date());
        console.log("check");
        if((timeend - nowtime) > 300000){
            timeToReturn();
        }
        setTimeout(check,10000);
    }
    setTimeout(check,10000);
    
})
Copy after login

This article comes from the js tutorial column, welcome to learn!

The above is the detailed content of The role of $(function()) in jQuery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template