最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用純css禁用html中a標(biāo)簽無需JavaScript

  發(fā)布時(shí)間:2014-05-13 17:28:56   作者:佚名   我要評(píng)論
時(shí)至今日,依然沒有找到使用純css禁用a標(biāo)簽的辦法,難道真的必須要借助JavaScript嗎?其實(shí)不然,方法有很多,下面為大家介紹下通過js、jquey以及css來實(shí)現(xiàn)禁用a標(biāo)簽
其實(shí)這個(gè)問題在初次學(xué)習(xí)html中select標(biāo)簽時(shí)就已經(jīng)冒出來了,時(shí)至今日,依然沒有找到使用純css禁用a標(biāo)簽的辦法——同事、同學(xué)、老師我都問過了,他們都千篇一律借助了JavaScript,難道真的必須要借助JavaScript嗎?

1、純css實(shí)現(xiàn)html中a標(biāo)簽的禁用:

復(fù)制代碼
代碼如下:

<html>
<head>
<title>如何禁用a標(biāo)簽</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" >百度</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<aclass="disableCss" href="#"onclick="javascript:alert('你好?。。?);">點(diǎn)擊</a>
</body>
</html>

上面雖然使用純css實(shí)現(xiàn)了對(duì)a標(biāo)簽的禁用,不過由于opera、ie瀏覽器不支持pointer-events樣式,所以上面代碼在這兩類瀏覽器中起不到禁用a標(biāo)簽的作用。

2、借助Jquery和css實(shí)現(xiàn)html中a標(biāo)簽的禁用:

復(fù)制代碼
代碼如下:

<html>
<head>
<title>02 ——借助Jquery和css實(shí)現(xiàn)html中a標(biāo)簽的禁用</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標(biāo)簽中的href屬性
$('.disableCss').removeAttr('onclick');//去掉a標(biāo)簽中的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" >百度</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a class="disableCss" href="#" onclick="javascript:alert('你好?。?!');">點(diǎn)擊</a>
</body>
</html>

這種方式可以兼容所有瀏覽器,可是混用了JavaScript,這一點(diǎn)恐怕是致命的缺憾?。?!

3、借助Jquery實(shí)現(xiàn)html中a標(biāo)簽的禁用:

復(fù)制代碼
代碼如下:

<html>
<head>
<title>03 ——借助Jquery實(shí)現(xiàn)html中a標(biāo)簽的禁用</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標(biāo)簽中的href屬性
$('.disableCss').removeAttr('onclick');//去掉a標(biāo)簽中的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" >百度</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a class="disableCss" href="#" onclick="javascript:alert('你好?。?!');">點(diǎn)擊</a>
</body>
</html>

上面使用了純Jquery實(shí)現(xiàn)了禁用html中a標(biāo)簽的功能。

相關(guān)文章

最新評(píng)論

东城区| 陈巴尔虎旗| 登封市| 交城县| 隆德县| 平阳县| 北川| 清镇市| 洛阳市| 台州市| 墨竹工卡县| 阳曲县| 施甸县| 天水市| 文安县| 彰武县| 富蕴县| 吴江市| 长春市| 盐亭县| 竹溪县| 三明市| 山东省| 云龙县| 呼玛县| 英吉沙县| 镇宁| 河北省| 金乡县| 黎川县| 叶城县| 石狮市| 偃师市| 镇康县| 高州市| 石林| 五常市| 友谊县| 普洱| 望谟县| 西盟|