gpt4 book ai didi

javascript - 如何在网页中嵌入隐藏数据并使用 DOM 恢复它?

转载 作者:行者123 更新时间:2023-12-03 07:26:10 25 4
gpt4 key购买 nike

我有一个网页,它从其他几个本地(同源)网页中提取数据。我使用 XMLHttpRequest 从这些其他网页收集数据。然后我使用 DOM 从每个页面解析出所需的数据。我想在每个其他本地页面中包含一条数据(即,在每个其他本地页面的 DOM 中),但是,我不希望在查看网页时该数据可见。 (在源代码中可见是可以的,只是在渲染的 HTML 中不可见)。我可以想到几种方法来做到这一点。然而,我对其中任何一个都不感兴趣。我想知道其他人可能有什么建议。感谢您的任何意见。

最佳答案

一些选项:

  • The hidden attribute :

    All HTML elements may have the hidden content attribute set. The hidden attribute is a boolean attribute. When specified on an element, it indicates that the element is not yet, or is no longer, directly relevant to the page's current state, or that it is being used to declare content to be reused by other parts of the page as opposed to being directly accessed by the user. User agents should not render elements that have the hidden attribute specified.

  • The template element

    The template element is used to declare fragments of HTML that can be cloned and inserted in the document by script.

    In a rendering, the template element represents nothing.

  • Comments

根据语义,您可以选择其中之一。或者甚至将它们结合起来:

<template hidden><!-- Hidden data --></template>

关于javascript - 如何在网页中嵌入隐藏数据并使用 DOM 恢复它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36000582/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com