javascript 内部html 问题

发布于 2024-09-02 17:07:32 字数 166 浏览 0 评论 0原文

我正在尝试获取节点的innerHTML 值。该值为D&O。当我尝试使用innerHTML 获取此值时,我得到D &amp[分号] O。是否有任何选项可以获取确切的值而不是使用Javascript 的编码值?请帮我。

论坛阻止我在 &amp 之后输入分号

I'm trying to get the innerHTML value of a node. The value is D&O. When I try to get this value using innerHTML I'm getting D &[semicolon] O. Is there any option to get the exact value rather than encoded value using Javascript? Please help me.

Forum prevents me from entering semicolon after &

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清风疏影 2024-09-09 17:07:32

您可以使用

 return ("innerText" in node) ? node.innerText : node.textContent;

innerHTML 来返回提供您看到的文本的等效 HTML。

You can use

 return ("innerText" in node) ? node.innerText : node.textContent;

innerHTML will returns the equivalent HTML that would provide the text that you see.

辞旧 2024-09-09 17:07:32
element.firstChild.data;

获取元素包含的文本节点中的数据。如果您需要文本而不是表示它的 HTML,请不要使用innerHTML。

element.firstChild.data;

Get the data in the text node contained in the element. If you want the text and not HTML that represents it, don't use innerHTML.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文