Anchor href 属性

Anchor 对象参考手册 Anchor对象

定义和用法

href 属性可设置或返回链接中 href 属性的值。

href 属性指定了被链资源的 URL。

语法

设置 href 属性:

anchorObject.href="URL"

返回 href 属性:

anchorObject.href

描述
URL被链资源的 URL


浏览器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要浏览器都支持 href 属性


实例

实例

返回链接中 href 属性的值:

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>小鸟启蒙(facesoho.com)</title> </head> <body> <p><a id="facesoho" href="//www.facesoho.com/">小鸟启蒙</a></p> <script> document.write("返回 href 链接: "); document.write(document.getElementById('facesoho').href); </script> </body> </html>

尝试一下 »


Anchor 对象参考手册 Anchor对象