[英]Reset dropdown at page refresh or back/forward browser navigation
Is there a simple command to restart all, or some included javascripts? 是否有一个简单的命令来重新启动所有或一些包含的javascripts? The problem I´ve got is that by refreshing page or pressing the back/forward key in the browser, some javascripts look like cached.
我遇到的问题是,通过刷新页面或按下浏览器中的后退/前进键,一些javascripts看起来像缓存。
Maybe like codepen it does? 它可能像codepen一样吗?
UPDATE: I found out, that this is only a problem for my "dropdowns". 更新:我发现,这对我的“下拉”来说只是一个问题。 So I have to reset them, if I refresh the browser and/or press back/forward.
所以我必须重置它们,如果我刷新浏览器和/或按后退/前进。 Any simple way?
任何简单的方法?
UPDATE: Ok, that works for me: 更新:好的,这对我有用:
$(':input').not(":button").val('');
});
No, I found out that this is a "dropdown" problem - so, I want to reset them by browser refresh and/or forward/backward.
不,我发现这是一个“下拉”问题 - 所以,我想通过浏览器刷新和/或前进/后退来重置它们。
To reset dropdowns to default value, you could use: 要将下拉列表重置为默认值,您可以使用:
$(window).on("pageshow", function() {
$('select').prop('selectedIndex', function () {
var selected = $(this).children('[selected]').index();
return selected != -1 ? selected : 0;
});
});
This is because the browser used a cached version of the page when you clicked the back button, it is called a bfcache
. 这是因为当您单击后退按钮时,浏览器使用了页面的缓存版本,它被称为
bfcache
。
You could try to add an empty unload handler like $(window).unload(function(){});
您可以尝试添加一个空的卸载处理程序,如
$(window).unload(function(){});
to disable the cache. 禁用缓存。
More info here: http://madhatted.com/2013/6/16/you-do-not-understand-browser-history 更多信息: http : //madhatted.com/2013/6/16/you-do-not-understand-browser-history
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.