Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> HTML

คุณสมบัติ view ของ Event ใน HTML

คุณสมบัติ view ของ Event ใน HTML ใช้คืนค่าการอ้างอิงถึงออบเจ็กต์ Window ที่เหตุการณ์เกิดขึ้น

ไวยากรณ์

event.view

ตัวอย่าง

<!DOCTYPE html>
<html>
<style>
  body { color: #000; height: 100vh; background-color: #FBAB7E; background-image: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%); text-align: center; }
  .btn { background: #db133a; border: none; height: 2rem; border-radius: 2px; width: 40%; display: block; color: #fff; outline: none; cursor: pointer; margin: 1rem auto; }
</style>
<body>
<h1>คุณสมบัติ view Event ของ HTML</h1>
<button class="btn" onclick="get()">แสดง view event</button>
<div class="show"></div>
<script>
  function get() {
    document.querySelector(".show").innerHTML = "เปิดคอนโซลและสังเกตออบเจ็กต์ Window";
    console.log(event.view);
  }
</script>
</body>
</html>

ผลลัพธ์

คลิกปุ่ม "แสดง view event" เพื่อแสดงออบเจ็กต์ Window

เปิดคอนโซลเบราว์เซอร์เพื่อดูออบเจ็กต์ Window ที่ล็อกไว้