用HTC文件,为按钮添加 link 和 target 属性
来源:互联网 发布:服装企业软件 编辑:程序博客网 时间:2024/06/05 15:54
做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'>
<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='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>
<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属性就不执行了,毕竟默认的属性优先吗。
类别:网页作坊 | 浏览(28)
网友评论:
- 用HTC文件,为按钮添加 link 和 target 属性
- 用HTC文件,为按钮添加 link 和 target 属性
- 用HTC文件,为按钮添加 link 和 target 属性
- 为launcher添加仿HTC的preview
- 为category添加属性和成员变量
- prototype为对象添加属性和方法
- 为按钮添加图标
- jsp页面中动态添加上传输入项注意的问题:“添加上传文件”按钮的name属性值不能和onclick属性的值相同!!!
- IOS项目笔记——按钮属性和代码添加
- 给LinkButton添加href、target属性
- 用VC++6.0为对话框添加最小化按钮和提示条
- QT用信号和处理机制为事件添加处理动作(点击按钮显示helloworld)
- targetSdkVersion和与target属性
- 为FCK编辑器(FCKEditor)添加新按钮和功能
- 为GRIDVIEW“删除”列和Button按钮添加确认对话框
- 为vc按钮添加背景颜色和字体颜色
- JTable 为单元格添加按钮效果和事件效果
- JTable 为单元格添加按钮效果和事件效果
- 风险评估工具
- 现在的是固定不变的未来说不定
- Windows下DB2分区实验方案(转载)
- The Linux Kernel Module Programming Guide(1)
- .Net Reflection机制
- 用HTC文件,为按钮添加 link 和 target 属性
- 用JSP连接mysql数据库
- 第一天写博客
- 实现排序优化的层次关系表设计
- FreeBSD非法改装全记录(1)轻装上阵
- 书评-虚拟化技术的世界,远比你想象的宽广
- 开始研究吧
- JSP与Servlet乱码问题解决办法
- Human-Robot Interaction based on Haar-like Features and Eigenfaces 学习心得及相关的较好的网站