msdn这么说的 Syntax bSuccess = object.attachEvent(sEvent, fpNotify)Res 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 Component (HTC) PUBLIC:ATTACH element automatically stops receiving notifications when the behavior detaches from the element, and does not need to call the detachEvent method. 特别是res中的 When sEvent fires on the object, the object's sEvent handler is called before fpNotify , the specified function这句,为什么我的onBlur没有先调用呢?
你这么试试. 把alert('1')写在一个函数里,先执行alert,在加behavior,但是要先把style的行为去掉. function a() { alert('1') document.all.inputId.addBehavior("url") }
http://flyingbug.blogone.net
supertoto(超级马桶),我看看先:)
“如果需要调用window对象的event属性那么就需要在htc中使用window.event”
你的例子说的不太清楚啊,你能够针对我的问题来说一下吗?
Syntax
bSuccess = object.attachEvent(sEvent, fpNotify)Res
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 Component (HTC) PUBLIC:ATTACH element automatically stops receiving notifications when the behavior detaches from the element, and does not need to call the detachEvent method.
特别是res中的
When sEvent fires on the object, the object's sEvent handler is called before fpNotify , the specified function这句,为什么我的onBlur没有先调用呢?
function a()
{
alert('1')
document.all.inputId.addBehavior("url")
}
按照HTC的规范,是HTC的作用域先起作用,所以你的alert没有发挥作用。你现在如果想外面元素的onBlur事件和HTC的onBlur事件同时起作用,那么你必须区分开两个作用域。如果你仍然是attach了onBlur事件给HTC,那么你是没有办法调用到元素的onBlur的。解决办法:一是将你在元素中的alert方法写到HTC中去,我想不出什么理由能让楼主不写到HTC中去;二是自定义一个事件,在元素的onBlur事件方法执行结束以后fire这个自定义的时间,调用HTC中的方法。不知道这样楼主清楚了我的意思没有。Good Luck.
现在我的办法就是指定一个属性,根据是否有这个属性来判断是否执行alert。
二是自定义一个事件,在元素的onBlur事件方法执行结束以后fire这个自定义的时间,调用HTC中的方法。
这个也不错!