Document: phương thức createComment()
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
createComment() tạo một nút chú thích mới và trả về nó.
Cú pháp
js
createComment(data)
Tham số
data-
Một chuỗi chứa dữ liệu cần được thêm vào Comment.
Giá trị trả về
Một đối tượng Comment mới.
Ví dụ
js
const doc = new DOMParser().parseFromString("<xml></xml>", "application/xml");
const comment = doc.createComment(
"This is a not-so-secret comment in your document",
);
doc.querySelector("xml").appendChild(comment);
console.log(new XMLSerializer().serializeToString(doc));
// Displays: <xml><!--This is a not-so-secret comment in your document--></xml>
Đặc tả kỹ thuật
| Specification |
|---|
| DOM> # ref-for-dom-document-createcomment①> |