element.location.href=element.href;href是location对象的一个属性而已

解决方案 »

  1.   

    我的意思是location这个对象是哪个对象的属性。
      

  2.   

    我的关键问题在
    element.location.href=element.href;
    就会报错
    这个问题
      

  3.   

    晕,在一般的js或html中,我肯定知道dom结构,但是进一步到htc中来使用,由于htc中element对象是作为默认对象,所以我想知道,
    function GotoLink()
    {
    if(element.href)
    {
    location.href=element.href;
    }
    }中在htc中,location属于谁的属性。
      

  4.   

    to  smartcoffee(coffee) 
    属于element,除非你加上window.location
      

  5.   

    呵呵,但是这个方式我也试过。我用HTC写的是一个element behavior,而不是attach behavior,不信你可以试试。我用
    element.location.href=element.href;
    代替
    location.href=element.href;
    就会报错。
    理论上说的在实践中过不了。所以我很迷惑。
      

  6.   

    在这里
    element代表的是A元素.
    A元素哪里来的location属性?
    在htc中,没有指明父对象的属性首先会被认定为window对象的属性.因为dom中window是顶层对象
      

  7.   

    但是在htc reference中清楚的说明了,没有指明父对象的属性默认为element.难道dom的规范和htc的规范有冲突?
      

  8.   

    前面的说法有误
    htc中任何方法及属性首先应该是element,
    如果element不具有该属性和方法,那么将被假定为属于window
      

  9.   

    考察如下htc
    <PUBLIC:COMPONENT>
    <PUBLIC:ATTACH EVENT="oncontentready" ONEVENT="Test()" />
    <PUBLIC:METHOD NAME="alert" />
    <SCRIPT LANGUAGE="JScript">
    function alert(param)
    {
    if(param==1)
    {
    window.alert("这是alert从element处调用,不指定element前缀")
    }
    if(param==2) 
    {
    window.alert("这是alert从element处调用,指定element前缀,需要对外发布为方法")
    }
    }
    function confirm(param)
    {
    if(param==1)
    {
    window.confirm("这是confirm从element处调用,不指定element前缀")
    }
    if(param==2) 
    {
    window.confirm("这是confirm从element处调用,指定element前缀,需要对外发布为方法")
    }
    }
    function Test()
    {
    alert(1);
    element.alert(2);
    window.alert("这是alert从window处被调用");
    confirm(1);
    try
    {
    element.confirm(2);
    }
    catch(e)
    {
    window.alert("由于confirm未对外发布,所以不能以element.confirm(2)方式调用")
    }
    window.confirm("这是confirm从window处被调用");
    }
    </SCRIPT>
    </PUBLIC:COMPONENT>