我有一个带有搜索表单的页面。当您第一次访问该页面时,我会触发 jQuery(document).ready():
jQuery(document).ready(
function () {
jQuery("#new_search").val(Math.round(new Date().getTime() / 1000));
}
);
现在,当您提交表单然后单击后退按钮时,document.ready 不会触发,但它需要触发。
最初的问题仅出现在 Firefox 中,但经过一些研究,我发现向正文添加卸载事件可以解决该问题:
jQuery(window).unload(function(){});
现在,我被告知它在 IE11 中不起作用。
有人对在 IE11 中触发 document.ready 函数有什么建议吗?
最佳答案
所以,我偶然发现了this answer在我的搜索中,埋在帖子的底部。
我试了一下,它有效:
// break the bfcache (ie11 and all others likely)
jQuery(window).focus(
function() {
jQuery("#new_search").val(Math.round(new Date().getTime() / 1000));
}
);
我原封不动地保留了原始代码,因为在我的例子中,我只是设置了一个unix时间戳,如果它发生多次也没关系。
完整答案:
jQuery(document).ready(
function () {
jQuery("#new_search").val(Math.round(new Date().getTime() / 1000));
}
);
jQuery(window).unload(function(){});
jQuery(window).focus(
function() {
jQuery("#new_search").val(Math.round(new Date().getTime() / 1000));
}
);
关于javascript - 在后退按钮 IE11 上触发 document.ready,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24023121/