Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> HTML

Đối tượng INS trong HTML DOM

Đối tượng INS trong HTML DOM đại diện cho phần tử <ins> - đánh dấu văn bản đã chèn thêm vào tài liệu (thường hiển thị gạch dưới).

Tạo ins object

document.createElement("INS");

Thuộc tính của ins object

Thuộc tínhMô tả
citeURL giải thích lý do chèn thêm (reference)
dateTimeThời gian chèn (định dạng ISO: YYYY-MM-DDThh:mm:ssTZD)

Ví dụ

<!DOCTYPE html>
<html>
<style>
  body { text-align: center; background-color: #fff; color: #0197F6; }
  h1 { color: #23CE6B; }
  .btn { background-color: #fff; border: 2px solid #0197F6; height: 2rem; width: 40%; margin: 2rem auto; display: block; color: #0197F6; outline: none; cursor: pointer; border-radius: 20px; }
  ins { text-decoration: underline; color: #23CE6B; }
  del { text-decoration: line-through; color: #db133a; }
</style>
<body>
<h1>Demo DOM INS Object</h1>
<button onclick="createIns()" class="btn">Tạo <ins> (văn bản chèn)</button>
<script>
  function createIns() {
    var insElement = document.createElement("INS");
    insElement.innerHTML = 'Văn bản MỚI được chèn thêm';
    insElement.cite = 'https://example.com/reason';
    insElement.dateTime = '2024-01-15T10:30:00Z';
    document.body.appendChild(insElement);
  }
</script>
</body>
</html>

Kết quả

Nhấn nút → xuất hiện văn bản gạch dưới "Văn bản MỚI được chèn thêm" với metadata cite/datetime.

Cặp đôi: <del> (xóa) + <ins> (chèn) cho version control, chỉnh sửa tài liệu cộng tác.