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
$(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.

$(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);
})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!