打印本文 打印本文 关闭窗口 关闭窗口
用HTC文件,为按钮添加 link 和 target 属性
作者:武汉SEO闵涛  文章来源:敏韬网  点击数971  更新时间:2009/4/23 11:12:49  文章录入:mintao  责任编辑:mintao
  做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属性就不执行了,毕竟默认的属性优先吗。

打印本文 打印本文 关闭窗口 关闭窗口