gpt4 book ai didi

javascript - 从 JSON 文件中读取带有 html 标签的内容并在 javascript 中显示

转载 作者:行者123 更新时间:2023-12-03 11:57:46 25 4
gpt4 key购买 nike

我有一个 JSON 文件,其中包含要在我的移动应用程序中显示的标签和内容。

我正在使用 $.getJSON 在我的项目中本地读取 JSON 文件。它将返回 JSON 对象。使用该对象,我在 Javascript 中显示标签/文本内容。当使用 html 字符显示内容时,它无法正确加载,但仍然显示 html 字符。

JSON 中的内容

 "CONSENT_EMAIL_REQUEST_BODY"  :   "Please read the below content <br> Welcome to the project <br> you can now use the application."

如果我尝试在 JavaScript 中打印 CONSENT_EMAIL_REQUEST_BODY 的值,它仍然显示

  Please read the below content <br> Welcome to the project <br> you can now use the application.

它没有逐行显示中断
按原样显示。如何替换这些 html 字符以在移动/浏览器中正确显示。

最佳答案

在打印之前,您必须将换行符
替换为 '\n'。

假设如果您将内容保存到变量 mycontent 中,那么您可以这样做:

mycontent = mycontent.replace(/<br\s*\/?>/mg,"\n");

然后打印我的内容。就是这样。

关于javascript - 从 JSON 文件中读取带有 html 标签的内容并在 javascript 中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25528539/

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