关于禁用html中a标签的思考
2014-05-12 12:54
441 查看
其实这个问题在初次学习html中select标签时就已经冒出来了,时至今日,依然没有找到使用纯css禁用a标签的办法——同事、同学、老师我都问过了,他们都千篇一律借助了JavaScript,难道真的必须要借助JavaScript吗?
1、纯css实现html中a标签的禁用:
<html>
<head>
<title>如何禁用a标签</title>
<metacontent="text/html; charset=GB2312"http-equiv="Content-Type">
<style type="text/css">
body{
font:12px/1.5 \5B8B\4F53, Georgia, Times New Roman, serif, arial;
}
a{
text-decoration:none;
outline:0 none;
}
.disableCss{
pointer-events:none;
color:#afafaf;
cursor:default
}
</style>
</head>
<body>
<aclass="disableCss" href="http://www.baidu.com/">百度</a>
<aclass="disableCss" href="#"onclick="javascript:alert('你好!!!');">点击</a>
</body>
</html>
上面虽然使用纯css实现了对a标签的禁用,不过由于opera、ie浏览器不支持pointer-events样式,所以上面代码在这两类浏览器中起不到禁用a标签的作用。
2、借助Jquery和css实现html中a标签的禁用:
<html>
<head>
<title>02 ——借助Jquery和css实现html中a标签的禁用</title>
<meta content="text/html; charset=GB2312" http-equiv="Content-Type">
<script type="text/javascript" src="./jquery-1.6.2.js"></script>
<script type="text/javascript">
$(function() {
$('.disableCss').removeAttr('href');//去掉a标签中的href属性
$('.disableCss').removeAttr('onclick');//去掉a标签中的onclick事件
});
</script>
<style type="text/css">
body {
font: 12px/1.5 \5B8B\4F53, Georgia, Times New Roman, serif, arial;
}
a {
text-decoration: none;
outline: 0 none;
}
.disableCss {
color: #afafaf;
cursor: default
}
</style>
</head>
<body>
<a class="disableCss" href="http://www.baidu.com/">百度</a>
<a class="disableCss" href="#" onclick="javascript:alert('你好!!!');">点击</a>
</body>
</html>
这种方式可以兼容所有浏览器,可是混用了JavaScript,这一点恐怕是致命的缺憾!!!
3、借助Jquery实现html中a标签的禁用:
<html>
<head>
<title>03 ——借助Jquery实现html中a标签的禁用</title>
<meta content="text/html; charset=GB2312" http-equiv="Content-Type">
<script type="text/javascript" src="./jquery-1.6.2.js"></script>
<script type="text/javascript">
$(function() {
$('.disableCss').removeAttr('href');//去掉a标签中的href属性
$('.disableCss').removeAttr('onclick');//去掉a标签中的onclick事件
$(".disableCss").css("font","12px/1.5 \\5B8B\\4F53, Georgia, Times New Roman, serif, arial");
$(".disableCss").css("text-decoration","none");
$(".disableCss").css("color","#afafaf");
$(".disableCss").css("outline","0 none");
$(".disableCss").css("cursor","default");
});
</script>
</head>
<body>
<a class="disableCss" href="http://www.baidu.com/">百度</a>
<a class="disableCss" href="#" onclick="javascript:alert('你好!!!');">点击</a>
</body>
</html>
上面使用了纯Jquery实现了禁用html中a标签的功能。
【0分demo下载】
1、纯css实现html中a标签的禁用:
<html>
<head>
<title>如何禁用a标签</title>
<metacontent="text/html; charset=GB2312"http-equiv="Content-Type">
<style type="text/css">
body{
font:12px/1.5 \5B8B\4F53, Georgia, Times New Roman, serif, arial;
}
a{
text-decoration:none;
outline:0 none;
}
.disableCss{
pointer-events:none;
color:#afafaf;
cursor:default
}
</style>
</head>
<body>
<aclass="disableCss" href="http://www.baidu.com/">百度</a>
<aclass="disableCss" href="#"onclick="javascript:alert('你好!!!');">点击</a>
</body>
</html>
上面虽然使用纯css实现了对a标签的禁用,不过由于opera、ie浏览器不支持pointer-events样式,所以上面代码在这两类浏览器中起不到禁用a标签的作用。
2、借助Jquery和css实现html中a标签的禁用:
<html>
<head>
<title>02 ——借助Jquery和css实现html中a标签的禁用</title>
<meta content="text/html; charset=GB2312" http-equiv="Content-Type">
<script type="text/javascript" src="./jquery-1.6.2.js"></script>
<script type="text/javascript">
$(function() {
$('.disableCss').removeAttr('href');//去掉a标签中的href属性
$('.disableCss').removeAttr('onclick');//去掉a标签中的onclick事件
});
</script>
<style type="text/css">
body {
font: 12px/1.5 \5B8B\4F53, Georgia, Times New Roman, serif, arial;
}
a {
text-decoration: none;
outline: 0 none;
}
.disableCss {
color: #afafaf;
cursor: default
}
</style>
</head>
<body>
<a class="disableCss" href="http://www.baidu.com/">百度</a>
<a class="disableCss" href="#" onclick="javascript:alert('你好!!!');">点击</a>
</body>
</html>
这种方式可以兼容所有浏览器,可是混用了JavaScript,这一点恐怕是致命的缺憾!!!
3、借助Jquery实现html中a标签的禁用:
<html>
<head>
<title>03 ——借助Jquery实现html中a标签的禁用</title>
<meta content="text/html; charset=GB2312" http-equiv="Content-Type">
<script type="text/javascript" src="./jquery-1.6.2.js"></script>
<script type="text/javascript">
$(function() {
$('.disableCss').removeAttr('href');//去掉a标签中的href属性
$('.disableCss').removeAttr('onclick');//去掉a标签中的onclick事件
$(".disableCss").css("font","12px/1.5 \\5B8B\\4F53, Georgia, Times New Roman, serif, arial");
$(".disableCss").css("text-decoration","none");
$(".disableCss").css("color","#afafaf");
$(".disableCss").css("outline","0 none");
$(".disableCss").css("cursor","default");
});
</script>
</head>
<body>
<a class="disableCss" href="http://www.baidu.com/">百度</a>
<a class="disableCss" href="#" onclick="javascript:alert('你好!!!');">点击</a>
</body>
</html>
上面使用了纯Jquery实现了禁用html中a标签的功能。
【0分demo下载】
相关文章推荐
- 关于禁用html中a标签的思考
- 关于把<script>标签放置的位置引发的关于html容错性的思考
- 关于 JSTL c:out 对 XML html 自动转义 转义的禁用
- 关于HTML标签的反转义函数
- 关于firefox获取不到HTML标签的file控件的完整路径解决方案
- 关于html音频以及视频标签video audio标签的实例
- 关于html标签中b和strong,i与em两个的区别 (转)
- 关于HTML在input标签内检测输入内容合法性和在js验证表单合法性后跳转到servlet的几点内容
- Html5+JQuery页面标签的禁用问题
- 关于迅盘Turbo Memory的ReadyDrive功能被禁用的思考
- HTML:关于a标签的target属性
- 关于html 头部meta标签。
- 关于angularJS绑定数据时自动转义html标签
- 关于IE和火狐,谷歌,Safari对Html标签Object和Embed的支持问题
- 关于HTML嵌套规则的思考
- 关于Android中如何过滤HTML标签
- 关于html 中a标签添加点击事件的方法总结
- js 在展示关于有 html标签 时候需要转义
- 关于Android中如何过滤HTML标签
- 关于jsp html标签的判断问题 if else 功能