写到htc中,
this.attachEvent("onblur", function(){fnBlur();alert('1');});

解决方案 »

  1.   

    你可以参考我刚刚翻译好的HTC使用文档,这是一个作用域的问题。
    http://flyingbug.blogone.net
      

  2.   

    我肯定不希望写到htc中去了
    supertoto(超级马桶),我看看先:)
      

  3.   

    还是没有太明白,你说
    “如果需要调用window对象的event属性那么就需要在htc中使用window.event”
    你的例子说的不太清楚啊,你能够针对我的问题来说一下吗?
      

  4.   

    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没有先调用呢?
      

  5.   

    你这么试试. 把alert('1')写在一个函数里,先执行alert,在加behavior,但是要先把style的行为去掉.
    function a()
    {
      alert('1')
      document.all.inputId.addBehavior("url")
    }
      

  6.   

    你这样只有第一次可以啊,那我还得在htc把这个behavior给去掉才能保证第二次也行了?
      

  7.   

    就是说你要分清楚作用域的概念,首先HTC本身是一个作用域,附着了HTC行为的元素是一个作用域,整篇文档是一个最大的作用域,你现在出现了一个要在一个元素的onBlur事件和HTC控件中的onBlur事件同名的问题,这里就涉及了第一和第二个作用域谁先起作用的问题,
    按照HTC的规范,是HTC的作用域先起作用,所以你的alert没有发挥作用。你现在如果想外面元素的onBlur事件和HTC的onBlur事件同时起作用,那么你必须区分开两个作用域。如果你仍然是attach了onBlur事件给HTC,那么你是没有办法调用到元素的onBlur的。解决办法:一是将你在元素中的alert方法写到HTC中去,我想不出什么理由能让楼主不写到HTC中去;二是自定义一个事件,在元素的onBlur事件方法执行结束以后fire这个自定义的时间,调用HTC中的方法。不知道这样楼主清楚了我的意思没有。Good Luck.
      

  8.   

    就是说没有办法在htc域处理了事件之后再把该事件转发的父元素了!
    现在我的办法就是指定一个属性,根据是否有这个属性来判断是否执行alert。
    二是自定义一个事件,在元素的onBlur事件方法执行结束以后fire这个自定义的时间,调用HTC中的方法。
    这个也不错!