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

วิธีสร้างข้อความขีดทับ (Strikethrough) ด้วย JavaScript

ใช้เมธอด strike() ของ String ทำให้ข้อความแสดงแบบขีดทับ เหมือนแท็ก <strike> (deprecated ใน HTML5 ใช้ <del> หรือ <s> แทน)

ตัวอย่าง

<html>
  <head>
    <title>JavaScript String strike() Method</title>
  </head>
  <body>
    <script>
      var str = new String("Demo Text");
      document.write(str.strike());
      alert(str.strike());
    </script>
  </body>
</html>

ผลลัพธ์

<strike>Demo Text</strike>

แนะนำ: ใช้ CSS text-decoration: line-through; หรือแท็ก <del> (deleted) / <s> (no longer accurate)