使用jQuery检测首页加载?

编程入门 行业动态 更新时间:2024-10-11 19:14:50
本文介绍了使用jQuery检测首页加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要检测第一次在jQuery中加载页面,以便只有在用户第一次导航到该页面时加载页面时才能执行某些操作。类似于服务器端代码页.ispostbasck。我已经测试了$(document).ready并且每次页面加载时它都会触发,所以这不会提供我需要的东西。我也尝试过jQuery Load函数 - 它还会触发每个页面加载。所以通过页面加载一个例子是我在类型按钮的页面上有一个HTML输入标签,它不会触发回发(如asp按钮),但它会重新加载页面并触发$(文档).ready

I need to detect the first time a page loads in jQuery so that I can perform some actions only when the page loads the first time a user navigates to that page. Similar to server side code page.ispostbasck. I have tested $(document).ready and it fires every time the page loads so this will not provide what I need. I have also tried the jQuery Load function - it also fires every page load. So by page load an example is that I have an HTML input tag on the page of type button and it does not fire a postback (like an asp button) but it does reload the page and fires $(document).ready

谢谢

推荐答案

您必须使用cookie存储首次加载信息:

You will have to use cookie to store first load information:

if (! $.cookie("cookieName")){ // do your stuff // set cookie now $.cookie("cookieName", "firstSet", {"expires" : 7}) }

注意:以上示例使用 jQuery Cookie插件。

更多推荐

使用jQuery检测首页加载?

本文发布于:2023-07-14 10:38:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1104130.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:首页   加载   jQuery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!