xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

document.createComment All In One

document.createComment All In One

document.createComment

document.createComment("auth")
<!--auth-->

image

MDN

XML / HTML

const docu = new DOMParser().parseFromString("<xml></xml>", "application/xml");
const comment = docu.createComment("This is a not-so-secret comment in your document");

docu.querySelector("xml").appendChild(comment);

console.log(new XMLSerializer().serializeToString(docu));
// <xml><!--This is a not-so-secret comment in your document--></xml>

image

https://developer.mozilla.org/en-US/docs/Web/API/Document/createComment

Comment

let comment = new Comment("Test");

console.log(`comment =`, comment)
// comment = <!--Test-->

image

https://mdn1.moz.one/en-US/docs/Web/API/Comment/Comment?language=en-US

https://developer.mozilla.org/en-US/docs/Web/API/Document/Comment

https://developer.mozilla.org/en-US/docs/Web/API/Comment/Comment

https://dom.spec.whatwg.org/#ref-for-dom-comment-comment①

demos

const removeElement = (el) => {
    // 在绑定元素上存储父级元素
    el._parentNode = el.parentNode
    // 在绑定元素上存储一个注释节点
    el._placeholderNode = document.createComment("auth")
    // 使用注释节点来占位
    el.parentNode?.replaceChild(el._placeholderNode, el)
}

https://juejin.cn/post/7209648356530896953

(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!

refs



©xgqfrms 2012-2021

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2023-07-12 23:36  xgqfrms  阅读(17)  评论(2编辑  收藏  举报