补上一篇的内容
上一篇

Binds the specified function to an event that fires on the object when the function is called.

Syntax

bSuccess = object.attachEvent(sEvent, fpNotify)

Parameters

sEvent Required. String that specifies any of the standard DHTML events.
fpNotify Required. Pointer that specifies the function to be called when sEvent fires.

Return Value

Boolean. Returns true if the function is bound successfully to the event, or false otherwise.

Remarks

When sEvent fires on the object, the object's sEvent handler is called before fpNotify, the specified function. If you attach multiple functions to the same event on the same object, the functions are called in random order, immediately after the object's event handler is called.

The attachEvent method enables a behavior to handle events that occur on the containing page. This method is not limited, however, to behaviors. You can also define a function on a page that attaches to events fired on the same page.

Behaviors that attach to events using the attachEvent method must explicitly call the detachEvent method to stop receiving notifications from the page when the ondetach event fires. A behavior that attaches to events on the page using the HTML Components (HTC) ATTACH element automatically stops receiving notifications when the behavior detaches from the element, and does not need to call the detachEvent method.

object.attachEvent方法可以为特定的对象的特定事件附加事件处理函数,不过上面也说了
通过此方法attach的事件处理函数会比用object.onEvent=handler指定的handler要晚执行
另外,还说明了一件事,如果你使用attachEvent方法attach多个函数的话,它们会都被执行,但是会"in randomize order"就是说,会按随机顺序执行,下面是我的测试代码
补:Javascript事件处理的串连function a()
,b);

经测试,Ie 6.0和Opera 8.0都可以正确的执行每个处事函数,但是FireFox只能执行使用onload指定的句柄,也就是说,firefox不支持attachevent,不过,它也不会报错哟.
还有一点,在ie 中,后attach的句柄先被执行,而在Opera中,先attach的句柄先执行

相关文章:

  • 2021-09-15
  • 2021-12-27
  • 2021-06-27
  • 2021-10-03
  • 2022-12-23
  • 2021-09-05
猜你喜欢
  • 2022-12-23
  • 2021-05-23
  • 2022-02-20
  • 2021-12-05
  • 2022-01-18
  • 2022-01-18
  • 2022-12-23
相关资源
相似解决方案