我只是用 JavaScript 和 < a href=" https://stackoverflow.com/a/1236378/575527" 测试用另一页取代整页。我找到了这个答案 使用 document.write
。关于为什么 document.write
,我需要用同一页替换整个 HTML,包括脚本和样式。
它按我的要求行事,但我似乎无法与我的事件处理器保持一致。 我的处理器都附在 document
上,使用:
$(document).delegate(...);
目前,我有一个怪异的结果。它附加了一个处理器。当点击时,事件火灾,重写页面,再次运行该函数 - 但是它不附加处理器 。
然而在我的项目中, 我仍然在做相同的常规 (d.w ()
, 然后添加操作员 ) 。 它确实一次重新连接, 操作员工作, 但在做第二个程序( 仍然在同一页上) 后, 它不再附加 。
所以,我的问题是:
- When using
d.w()
, do existing handlers get erased fromdocument
? - Are
window
as well asdocument
the same after subsequentd.w()
s? or are they somehow "renewed" - Do scripts that are already parsed stay in memory and run after subsequent
d.w()
s? Or do they get erased as well?