Link href 属性

定义和用法
href 属性是一个可读可写的字符串,可设置或返回当前显示的文档的完整 URL。
语法
设置 href 属性:
linkObject.href="URL"
返回 href 属性:
linkObject.href
浏览器支持
所有主要浏览器都支持 href 属性
实例
实例
点击一个按钮时切换样式表:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>小鸟启蒙(facesoho.com)</title>
<link id="style1" rel="stylesheet" type="text/css" href="style1.css">
<script>
function displayResult(){
document.getElementById("style1").href="style2.css";
}
</script>
</head>
<body>
<h1>我的网站主页</h1>
<button type="button" onclick="displayResult()">切换样式表</button>
</body>
</html>
<html>
<head>
<meta charset="UTF-8">
<title>小鸟启蒙(facesoho.com)</title>
<link id="style1" rel="stylesheet" type="text/css" href="style1.css">
<script>
function displayResult(){
document.getElementById("style1").href="style2.css";
}
</script>
</head>
<body>
<h1>我的网站主页</h1>
<button type="button" onclick="displayResult()">切换样式表</button>
</body>
</html>
尝试一下 »

尊贵的董事大人
英文标题不为空时 视为本栏投稿
需要关键字 描述 英文标题