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

วิธีทำเครื่องหมายข้อความที่ถูกลบ (Deleted Text) ใน HTML

แท็ก <del> ใช้สำหรับทำเครื่องหมายข้อความที่ถูกลบออกจากเอกสาร นำมาใช้ใน HTML5 แทนแท็ก <strike> ที่ถูก deprecated

คุณสมบัติ

  • Browser แสดงด้วยเส้นทับ (strikethrough) โดยค่าเริ่มต้น
  • มี attribute cite ระบุ URL อธิบายเหตุผลการลบ
  • มี attribute datetime ระบุวันเวลาที่ลบ (ISO 8601)
  • ต้องมี opening และ closing tag คู่กัน
  • ควรวางภายใน <p> หรือ block-level element

ตัวอย่าง

<!DOCTYPE html>
<html>
<head>
  <title>HTML del tag</title>
</head>
<body>
  <h1>Heading</h1>
  <p>
    This is demo text. <del cite="https://example.com/reason" datetime="2024-01-15">This text is deleted</del>
  </p>
</body>
</html>

ผลลัพธ์

This is demo text. This text is deleted

การใช้งานร่วมกับ ins

<p>ราคา: <del>1,000 บาท</del> <ins>750 บาท</ins></p>

ราคา: 1,000 บาท 750 บาท