• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

用HTC文件,为按钮添加 link 和 target_html

html 搞代码 7年前 (2018-06-15) 158次浏览 已收录 0个评论
  做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属性就不执行了,毕竟默认的属性优先吗。

欢迎大家阅读《用HTC文件,为按钮添加 link 和 target_html,跪求各位点评,若觉得好的话请收藏本文,by 搞代码


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:用HTC文件,为按钮添加 link 和 target_html
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址