如何使用javascript检查页面是否首次加载 [英] how to check if page is loaded for the first time using javascript
本文介绍了如何使用javascript检查页面是否首次加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检查页面是否是第一次加载,然后显示该过滤器.如果我将showFiltermenu()放在pageLoad函数中,那么它将在每次页面加载时显示,但我只希望它第一次显示.我尝试使用Page.IsPostBack
,但是不显示过滤器.
I want to check if the page is being loaded for the first time, and if it is then display the filter. If I put showFiltermenu() in the pageLoad function then it will show every time the page is loaded but I just want it display the first time. I tried using Page.IsPostBack
but that doesn't display the filter.
<script type="text/javascript">
function showFiltermenu() {
$("#filtermenuDrop").toggle('fold', {}, 500);
}
function closefiltermenu() {
$("#filtermenuDrop").toggle('fold', {}, 500);
}
function pageLoad() {
$("input[rel^='datepicker']").datepicker({
dateFormat: 'dd/mm/yy',
changeMonth: true,
yearRange: "c-50:c+50",
changeYear: true,
showOn: "both",
firstDay: 1,
buttonImage: "../images/icons/buttons/basic1-049-small.png"
});
<% if (Page.IsPostBack)
{ %>
showFiltermenu();
<% } %>
ShadowboxInit();
}
推荐答案
感谢每个人的回答,但是我的问题中只有一个简单的错误.我在if语句中忘记了!
.现在可以检查页面是否是第一次加载.
Thanks everyone for their answers but there was just a simple mistake in my question. I forgot the !
in the if statement. This now works to check if the page is loaded for the first time.
<% if (!Page.IsPostBack)
{ %>
showFiltermenu();
<% } %>
这篇关于如何使用javascript检查页面是否首次加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文