element.location.href=element.href;href是location对象的一个属性而已
解决方案 »
- js 正则表达式的exec方法是怎么使用的啊?
- js动态添加文本框
- js 代码转换 兼容各浏览器
- 能否用innerHTML改变table的内容
- 请高人出手帮忙给js文件解密:分数就这么多了,解完以后再多给
- 怎样移除ext里formpanel里的Field或items
- encodeURIComponent中文乱码如何解决?
- 键盘配合鼠标,实现链接的不同打开方式!!!
- javascript能不能定义公用变量??
- 上面的两个函数不太懂,能帮说一下是什么意思吗?javascript
- 急求!frame信息互传功能!高手请进,在线等待!
- 有什么方法在两个不同的网页中传递信息??(不通过服务器端(JSP,ASP),而是直接通过客户端实现(如javascript等))??
element.location.href=element.href;
就会报错
这个问题
function GotoLink()
{
if(element.href)
{
location.href=element.href;
}
}中在htc中,location属于谁的属性。
属于element,除非你加上window.location
element.location.href=element.href;
代替
location.href=element.href;
就会报错。
理论上说的在实践中过不了。所以我很迷惑。
element代表的是A元素.
A元素哪里来的location属性?
在htc中,没有指明父对象的属性首先会被认定为window对象的属性.因为dom中window是顶层对象
htc中任何方法及属性首先应该是element,
如果element不具有该属性和方法,那么将被假定为属于window
<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>