HTML DOM Link href 属性

Link href 属性

Link 对象参考手册 Link 对象

定义和用法

href 属性是一个可读可写的字符串,可设置或返回当前显示的文档的完整 URL。

语法

设置 href 属性:

linkObject.href="https://zhishitu.com/" target="_blank"

返回 href 属性:

linkObject.href

浏览器支持

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

实例

实例

点击一个按钮时切换样式表:


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>知识兔(zhishitu.com)</title>
<link id="style1" rel="stylesheet" type="text/css" href="https://zhishitu.com/" target="_blank">
<script>
function displayResult(){
    document.getElementById("style1").href="https://zhishitu.com/" target="_blank";
}
</script>
</head>
<body>
    
<h1>我的网站主页</h1>
<button type="button" onclick="displayResult()">切换样式表</button>

</body>
</html>

知识兔 »
Link 对象参考手册 Link 对象
计算机