HTML DOM Link href 속성은 링크된 문서의 경로/URL을 설정/반환합니다. -
구문
다음은 구문입니다 -
- href 반환 속성 값
linkObject.href
- href 설정 문자열로
linkObject.href = string
부울 값
여기서 "문자열"은 다음과 같을 수 있습니다. -
| booleanValue | 세부정보 |
|---|---|
| 경로 | 문서에 대한 절대/상대 경로를 정의합니다. |
| URL | 링크할 문서의 URL 주소를 정의합니다. |
예시
Link href의 예를 살펴보겠습니다. 속성 -
<!DOCTYPE html>
<html>
<head>
<title>Link href</title>
<link id="extStyle" rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<form>
<fieldset>
<legend>Link-href</legend>
<label for="WeekSelect">Sales Target Week:
<input type="week" id="WeekSelect" value="2020-W13" disabled>
</label>
<input type="button" onclick="enableWeekInput()" value="Change Sales Target Week">
<input type="button" onclick="changeStyle()" value="Change Style">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var inputWeek = document.getElementById("WeekSelect");
var extStyle = document.getElementById("extStyle");
divDisplay.textContent = 'Week Input disabled: '+inputWeek.disabled;
function enableWeekInput() {
inputWeek.disabled = false;
divDisplay.textContent = 'Week Input disabled: '+inputWeek.disabled;
}
function changeStyle(){
extStyle.href = 'anotherStyle.css';
}
</script>
</body>
</html> 위의 예에서 'style.css' 포함 -
form {
width:70%;
margin: 0 auto;
text-align: center;
}
* {
padding: 2px;
margin:5px;
}
input[type="button"] {
border-radius: 10px;
} 위의 예에서 'anotherStyle.css' 포함 -
form {
width:70%;
margin: 0 auto;
text-align: center;
background-color: rgba(0,0,0,0.7);
color: white;
}
* {
padding: 2px;
margin:5px;
}
input[type="button"] {
border-radius: 10px;
} 출력
이것은 다음과 같은 출력을 생성합니다 -
'스타일 변경'을 클릭하기 전에 버튼 -

'스타일 변경'을 클릭한 후 버튼 -
