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

อ็อบเจ็กต์ Underline ของ HTML DOM

อ็อบเจ็กต์ Underline ใน HTML DOM แทนองค์ประกอบ <u> ซึ่งใช้แสดงข้อความที่มีเส้นใต้ (underline)

การสร้างองค์ประกอบ <u>

var uObject = document.createElement("U")

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

ตัวอย่างนี้เปลี่ยนสีพื้นหลังและสีตัวอักษรของข้อความที่มีเส้นใต้เมื่อกดปุ่ม

<!DOCTYPE html>
<html>
<head>
<title>HTML DOM Underline</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>HTML-DOM-Underline</legend>
      <h2><u id="Underline">Warning: </u>This is a Demo Example</h2>
      <input type="button" value="Show" onclick="getBetterDisp()">
    </fieldset>
  </form>
<script>
  var uObject = document.getElementById("Underline");
  function getBetterDisp() {
    uObject.style.backgroundColor = '#DC3545';
    uObject.style.color = '#FFF';
  }
</script>
</body>
</html>

ผลลัพธ์ (Output)

ก่อนกดปุ่ม "Show":

อ็อบเจ็กต์ Underline ของ HTML DOM

หลังกดปุ่ม "Show":

อ็อบเจ็กต์ Underline ของ HTML DOM