English 中文(简体)
javascript:<one onload="> 页: 1
原标题:javascript: <body onload=""> and window.onload

我今天经历过一个不容置疑的错误。 我有一个简单的用户说明,为所有网站添加了<代码>window.onload活动。 但是,其中一个站点有<代码><载体=“func();”>下定义。 实际情况是,<代码>window.onload正在按惯例开展工作,但<上载人=”>在安装用户文字后停止在现场工作。

当我使用<代码>window.oneload时,两者都做得很好。 我知道,window.onload and < person onload=”> 是做同一事情的不同方式,但发生在window. .onload。 哪一使之与<代码><、载体=”>、良好运作?

最佳回答

正如Myforwik所说,你用window.onload = ......;是你用<、上载人<>>>、所记的同一事件。 <代码>windowload. 这两种穿刺方式都是旧的DOM0型,有些时间已经过时。 如果你明确这两者,后者将获胜,战胜前者。 如果多字母代码window.onload独立,情况也是如此。

为了避免这类问题,利用DOM2-型活动:

if (window.addEventListener) {
    // DOM2 standard
    window.addEventListener("load", handler, false);
}
else if (window.attachEvent) {
    // Microsoft s precursor to it, IE8 and earlier
    window.attachEvent("onload", handler);
}
else {
    // Some pre-1999 browser
    window.onload = handler;
}

function handler() {
}

多个DOM2处理器可以附属于同一活动,因此可以订阅多种与外界无关的文字。 此外,DOM2处理器与DOM0处理器共同操作。

因此,如果您更新用户文字,以使用上述文字,<代码><上载人=......>>页将不受影响。

问题回答

载荷为same活动。 因此,如果你以两种不同的方法两次确定同一事件,那么,它只能以一种价值——一种功能——结束。

窗户。 仅是DoM的另一座qui,还有哪座wer子。





相关问题
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.

热门标签