English 中文(简体)
文档. wwride 和 授权的事件处理员的持久性
原标题:document.write and delegated event handler persistence
  • 时间:2012-05-26 13:41:43
  •  标签:
  • javascript

我只是用 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 from document?
  • Are window as well as document the same after subsequent d.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?
最佳回答
问题回答

它从第二次开始停止工作的唯一原因 是因为在你的职务中 你写了

document.write( <span> +(++i)+ </span> );

在这种情况下, 下次文件没有代表功能来递增范围值, 但只有您在前面我所强调代码片断中写的内容。 因此, 正如您所怀疑的那样, 他们也会被删除 。 希望这有帮助 。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签