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

คุณสมบัติ sizes ของ Link ใน HTML DOM

คุณสมบัติ sizes ของอีลีเมนต์ <link> ใช้ดึงค่าแอตทริบิวต์ sizes (ใช้ได้ก็ต่อเมื่อ rel="icon")

⚠ หมายเหตุ: คุณสมบัติ sizes ใช้งานได้เฉพาะเมื่อ rel ถูกตั้งเป็น 'icon' เท่านั้น

ไวยากรณ์ (Syntax)

linkObject.sizes

ตัวอย่างการใช้งาน

ตัวอย่างด้านล่างตรวจสอบขนาดไอคอนที่ลิงก์:

<!DOCTYPE html>
<html>
<head>
<title>Link sizes</title>
<link id="extStyle" rel="icon" href="new.gif" sizes="10x10">
</head>
<body>
<form>
  <fieldset>
    <legend>Link-sizes</legend>
    <div id="divDisplay"></div>
  </fieldset>
</form>
<script>
  var divDisplay = document.getElementById("divDisplay");
  var extStyle = document.getElementById("extStyle");
  
  if(extStyle.sizes == '10x10')
    divDisplay.textContent = 'The linked icon size: ' + extStyle.sizes + ' is not compatible';
  else
    divDisplay.textContent = 'Congrats! The linked icon size is compatible';
</script>
</body>
</html>

ผลลัพธ์

แสดง "The linked icon size: 10x10 is not compatible" (เพราะเงื่อนไขตรวจสอบเป็น 10x10)

หมายเหตุ: รูปภาพตัวอย่างจากต้นฉบับไม่ได้รวมอยู่ในเนื้อหานี้