gpt4 book ai didi

javascript - 使用 JavaScript 向 html 元素写入额外的空格

转载 作者:行者123 更新时间:2023-12-04 02:25:57 24 4
gpt4 key购买 nike

我们有 JavaScript 写入文档标题并尝试用额外的空格填充它...

document.title = "My Title  "

但这会被翻译成“My Title  ”

有人知道如何防止这种情况发生吗?

最佳答案

  是一个 HTML entity reference表示字符引用  (参见 list of entities in HTML 4),它再次表示 Unicode 字符 U+00A0。现在document.title类型为 DOMString that is similar to CDATA那个值没有被解析。这意味着您不能对 document.title 使用 HTML 引用,因为该值未被解析为 HTML。

尝试使用 Javascript 的 Unicode 转义序列来表示这些字符,如下所示:

document.title = "My Title\u00A0\u00A0"

关于javascript - 使用 JavaScript 向 html 元素写入额外的空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3751793/

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