足球游戏_中国足彩网¥体育资讯$

使用纯css禁用html中a标签无需JavaScript
来源:易贤网 阅读:16345 次 日期:2014-05-14 21:36:50
温馨提示:易贤网小编为您整理了“使用纯css禁用html中a标签无需JavaScript”,方便广大网友查阅!

1、纯css实现html中a标签的禁用:

代码如下:

<html>

<head>

<title>如何禁用a标签</title>

<metacontent="text/html; charset=gbk"http-equiv="Content-Type">

<styletype="text/css">

body{

font:12px/1.5\5B8B\4F53,Georgia,TimesNewRoman,serif,arial;

}

a{

text-decoration:none;

outline:0none;

}

.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>

<metacontent="text/html; charset=gbk"http-equiv="Content-Type">

<scripttype="text/javascript"src="./jquery-1.6.2.js"></script>

<scripttype="text/javascript">

$(function(){

$('.disableCss').removeAttr('href');//去掉a标签中的href属性

$('.disableCss').removeAttr('onclick');//去掉a标签中的onclick事件

});

</script>

<styletype="text/css">

body{

font:12px/1.5\5B8B\4F53,Georgia,TimesNewRoman,serif,arial;

}

a{

text-decoration:none;

outline:0none;

}

.disableCss{

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>

这种方式可以兼容所有浏览器,可是混用了JavaScript,这一点恐怕是致命的缺憾!!!

3、借助Jquery实现html中a标签的禁用:

代码如下:

<html>

<head>

<title>03——借助Jquery实现html中a标签的禁用</title>

<metacontent="text/html; charset=gbk"http-equiv="Content-Type">

<scripttype="text/javascript"src="./jquery-1.6.2.js"></script>

<scripttype="text/javascript">

$(function(){

$('.disableCss').removeAttr('href');//去掉a标签中的href属性

$('.disableCss').removeAttr('onclick');//去掉a标签中的onclick事件

$(".disableCss").css("font","12px/1.5\\5B8B\\4F53,Georgia,TimesNewRoman,serif,arial");

$(".disableCss").css("text-decoration","none");

$(".disableCss").css("color","#afafaf");

$(".disableCss").css("outline","0none");

$(".disableCss").css("cursor","default");

});

</script>

</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>

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

中国足彩网信息请查看IT技术专栏

中国足彩网信息请查看网页制作
由于各方面情况的不断调整与变化,易贤网提供的所有考试信息和咨询回复仅供参考,敬请考生以权威部门公布的正式信息和咨询为准!
关于我们 | 联系我们 | 人才招聘 | 网站声明 | 网站帮助 | 非正式的简要咨询 | 简要咨询须知 | 加入群交流 | 手机站点 | 投诉建议
工业和信息化部备案号:滇ICP备2023014141号-1 足球游戏_中国足彩网¥体育资讯$ 滇公网安备53010202001879号 人力资源服务许可证:(云)人服证字(2023)第0102001523号
云南网警备案专用图标
联系电话:0871-65317125(9:00—18:00) 获取招聘考试信息及咨询关注公众号:hfpxwx
咨询QQ:526150442(9:00—18:00)版权所有:易贤网
云南网警报警专用图标