用HTC文件,为按钮添加 link 和 target 属性

王朝html/css/js·作者佚名  2006-12-17
宽屏版  字体: |||超大  

用HTC文件,为按钮添加 link 和 target 属性

用HTC文件,为按钮添加 link 和 target 属性 做WEB程序的时候经常需要用一个按钮来跳转到一个页面,或打开新窗口;由于按钮没有link属性,所以经常要写脚本来控制,感觉有些麻烦,最近看了一些关于HTC的文档,发现HTC可以为按钮添加属性,所以就写了个例子。 文件:test.htm <link href='style.css' rel='stylesheet' type='text/css'>

<input type=button link='http://www.sina.com.cn' value='打开新浪'>

<input type=button link='http://www.sina.com.cn' value='新窗口打开新浪' target='_blank'> 文件:style.css Input{behavior:url('input.htc');}

文件:input.htc <public:component><!--添加连接-->

<public:property name='link' value='' /><!--添加是否在新窗口打开属性-->

<public:property name='target' value='' />

<script language=javascript>

if(this.onclick==null)

{

onclick=function()

{

if (link!='')

{

if (target=='_blank')

{

window.open(link);

}

else

{

location.href=link;

}

}

};

};

</script>

</public:component> 把上面的代码分别保存,放在同一个目录下就可以了,以后只要引入了style.css,那么页面中的按钮就多了两个属性 link ,target。如果你设置了按钮的onclick属性,那么link属性就不执行了,毕竟默认的属性优先吗。

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有