这篇文章主要为大家详细介绍了jQuery中$(function())的作用是什么,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下。

jQuery中$(function())的作用
$(function())等同于$(document).ready(function()),意思很简单,就是等页面加载完毕之后,才开始执行函数。
在没有使用$(function())之前,我的$("body").click()的操作不起作用,先执行函数了,此时DOM并没有加载完成,所以不起效果。在将js函数放入$(function())后,就可正常运行。

$(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);
})
以上就是jQuery中$(function())的作用是什么的简略介绍,当然详细使用上面的不同还得要大家自己使用过才领会。如果想了解更多,欢迎关注天达云行业资讯频道哦!