您的位置 首页 技术

jQuery中$(function())的作用

本篇文章介绍了jQuery中$(function())的作用,具有一定的参考价值,希望对学习jQuery和JavaScript的朋友有帮助! jQuery中$(function()…

本篇文章介绍了jQuery中$(function())的作用,具有一定的参考价值,希望对学习jQuery和JavaScript的朋友有帮助!

jQuery中$(function())的作用

$(function())等同于$(document).ready(function()),意思很简单,就是等页面加载完毕之后,才开始执行函数。

在没有使用$(function())之前,我的$("body").click()的操作不起作用,先执行函数了,此时DOM并没有加载完成,所以不起效果。在将js函数放入$(function())后,就可正常运行。

微信截图_20200403180415.png

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

本文来自 js教程 栏目,欢迎学习!

以上就是jQuery中$(function())的作用的详细内容,更多请关注24课堂在线网其它相关文章!

本文来自网络,不代表24小时课堂在线立场,转载请注明出处:https://www.24ketang.cn/57758.html

为您推荐

返回顶部