南强小屋 Design By 杰米
其实这个问题在初次学习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>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<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="/UploadFiles/2021-03-30/jquery-1.6.2.js"><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>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<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="/UploadFiles/2021-03-30/jquery-1.6.2.js"><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>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a class="disableCss" href="#" onclick="javascript:alert('你好!!!');">点击</a>
</body>
</html>

上面使用了纯Jquery实现了禁用html中a标签的功能。
标签:
html,禁用a标签

南强小屋 Design By 杰米
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
南强小屋 Design By 杰米

评论“使用纯css禁用html中a标签无需JavaScript”

暂无使用纯css禁用html中a标签无需JavaScript的评论...

P70系列延期,华为新旗舰将在下月发布

3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。

而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?

根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。