用HTC文件,为按钮添加 link 和 target 属性
2005-08-06 09:30
218 查看
做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属性就不执行了,毕竟默认的属性优先吗。
<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 属性
- 用HTC文件,为按钮添加 link 和 target 属性
- Android 属性动画(Property Animation 给按钮的添加添加动画效果,同样可以用在整个布局上) (下)(viewGroup创建对象竟然可以用布局的id)
- ASP.NET 的后台代码问题:动态向Table里添加按钮,却提示没有Text属性。
- ios weibo 第二天 设置导航栏属性,添加加号按钮, 新特性
- UITextview 给给定的字符串添加link属性 指定字符串添加点击方法
- UIButton的相关属性/导航添加按钮
- 给LinkButton添加href、target属性
- 在属性框中添加其他按钮
- easyui按钮linkbutton添加disable属性
- jQuery动态添加.active属性实现按钮点击样式
- 批量添加target属性
- 按钮添加关闭页面属性
- 给LinkButton添加href、target属性
- 自绘按钮,添加Color属性(转载)
- jsp页面中动态添加上传输入项注意的问题:“添加上传文件”按钮的name属性值不能和onclick属性的值相同!!!
- IOS项目笔记——按钮属性和代码添加
- 给LinkButton添加href、target属性
- document.execCommand createLink 增加target属性
- A Link 链接的rel、target属性详解