ออบเจ็กต์ชื่อ HTML DOM ใน HTML แสดงถึงองค์ประกอบ
การสร้าง
var titleObject = document.createElement(“TITLE”)
ที่นี่ “titleObject” สามารถมีคุณสมบัติดังต่อไปนี้ −
| คุณสมบัติ | คำอธิบาย |
|---|---|
| ข้อความ | Itsets/returns ค่าของ |
เรามาดูตัวอย่างข้อความชื่อเรื่อง ทรัพย์สิน −
ตัวอย่าง
<!DOCTYPE html>
<html>
<head>
<title id="titleSelect">HTML DOM Title text</title>
<style>
form {
width:70%;
margin: 0 auto;
text-align: center;
}
* {
padding: 2px;
margin:5px;
}
input[type="button"] {
border-radius: 10px;
}
</style>
</head>
<body>
<form>
<fieldset>
<legend id="legendSelect"></legend>
<input type="button" onclick="getTitleText()" value="What's the title of document?">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var legendSelect = document.getElementById("legendSelect");
var titleSelect = document.getElementById("titleSelect");
function getTitleText() {
divDisplay.textContent = 'Title of document: '+titleSelect.text;
legendSelect.textContent = titleSelect.text.split(' ').join('-');
}
</script>
</body>
</html> ผลลัพธ์
ก่อนคลิก 'ชื่อเอกสารคืออะไร' ปุ่ม −

หลังจากคลิก 'ชื่อเอกสารคืออะไร' ปุ่ม −
