我在一些pug
文件中有以下javascript代码:
doctype html
html
//- this is not firing for some reason
head
script(type="text/javascript").
document.addEventListener('DOMContentLoaded', function() {
console.log('ready!')
}, false);
当我刷新页面时脚本才会运行,但是当我导航到页面时脚本不会触发。我正在寻找一个类似于onNavigate
的事件,但是在这里:https://www.w3schools.com/jsref/dom_obj_event.asp和这里:https://developer.mozilla.org/en-US/docs/Web/Events都没有看到。
DOMContentLoaded
事件已经触发了。 - Derek Pollarddocument.readyState
。 - Derek PollardDOMContentLoaded
应该在所有 HTML 加载完成后才触发,这样才能执行 JS。 - Barmar