html - css 这个 attr(href) 是什么用法?

查看:1220
本文介绍了html - css 这个 attr(href) 是什么用法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

这段代码,别的我都懂,就这个attr(href) 是怎么回事,
我知道jQuery 有这个方法,但是 也不是这么用 的!
是个什么用法?有个什么讲究?
其实我是想通过 这个 attr(href) 学到一些其他作用..

就是学了
document.getElementById(" ")
之后,
搜资料知道了
document.getElementsByTagName(" ")[0]
document.getElementsByTagClassName(" ")[0]


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<style>
a:after {content: " (" attr(href) ")";} /*★★★★★★这里的是 attr(href) 是什么意思?*/
</style>
</head>

<body>
<p><a href="http://www.w3cschool.cc">这个到底是啥?</a> contains free tutorials and references.</p>
<p><a href="http://www.wwwwwww.cc">大家好!!</a> contains free tutorials and references.</p>
<p><b>Note:</b> IE8 supports the content property only if a !DOCTYPE is specified.</p>
</body>
</html>

解决方案

如果没有加 a:after 那个样式,下面的链接应该显示成

这个到底是啥 contains ......

加了之后显示成

这个到底是啥 (http://www.w3cschool.cc) contains ......

看出来区别没得?

a:after 表示在 <a> 内容的后面,content: 表示要添加的内容,attr(href) 表示获取当前标签,即 <a>href 属性。

这篇关于html - css 这个 attr(href) 是什么用法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆