Javascript 无法刷新页面 [英] Javascript not working on page refresh
本文介绍了Javascript 无法刷新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我有这个代码块:
$(document).ready(function() {
planSelectionForm.init($("form#new_account"));
});
当我链接到此页面时,它会按预期工作.但是当我从浏览器刷新时,它不会被触发.这似乎是一个普遍的问题.只是为了记录,我正在使用 turbolinks.任何有关为什么会发生这种情况的帮助都会很棒!
And when I link to this page it works as expected. But when I refresh from the browser it doesn't get triggered. This seems like a common problem. Just for the record I'm using turbolinks. Any help on why this is happening would be great!
推荐答案
遇到这个问题后我能找到的唯一解决方案是将我的脚本包装成:
The only solution I could find after getting this problem was wrapping my script with:
document.addEventListener("turbolinks:load", function() {
planSelectionForm.init($("form#new_account"));
});
这篇关于Javascript 无法刷新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文