HTML DOM 옵션 텍스트 속성은 HTML 문서의 옵션 텍스트를 반환하고 수정합니다.
구문
다음은 구문입니다 -
1. 텍스트 반환
object.text
2. 텍스트 수정
object.text = “text”
예시
HTML DOM 옵션 텍스트 속성의 예를 살펴보겠습니다 -
<!DOCTYPE html>
<html>
<head>
<style>
html{
height:100%;
}
body{
text-align:center;
color:#fff;
background: radial-gradient( circle farthest-corner at 23.1% 64.6%, rgba(129,125,254,1) 0%, rgba(111,167,254,1) 90% ) no-repeat;
height:100%;
}
p{
font-weight:700;
font-size:1.1rem;
}
.drop-down{
display:block;
width:35%;
border:2px solid #fff;
font-weight:bold;
padding:2px;
margin:1rem auto;
outline:none;
}
.btn{
background:orange;
border:none;
height:2rem;
border-radius:2px;
width:35%;
margin:2rem auto;
display:block;
color:#fff;
font-weight:bold;
outline:none;
cursor:pointer;
}
.show{
font-size:1.5rem;
font-weight:bold;
}
</style>
</head>
<body>
<h1>DOM Option text Property Demo</h1>
<p>Hi, Select your favourite subject −</p>
<select class='drop-down'>
<option>Physics</option>
<option>Biology<option>
<option>Maths<option>
</select>
<button type="button" onclick="changePhysicsName()" class="btn">Change Physics
Subject Name</button>
<div class="show"></div>
<script>
function changePhysicsName() {
document.querySelector(".drop-down").options[0].text="Applied Physics";
document.querySelector(".show").innerHTML="Now Physics become Applied Physics";
}
</script>
</body>
</html> 출력
이것은 다음과 같은 출력을 생성합니다 -

"물리학 주제 이름 변경을 클릭합니다. ” 버튼을 눌러 물리 옵션의 텍스트를 변경합니다.
