javascript - 如何添加链接并突出显示从 json 文件接收到的数据
问题描述
如何向从 json 文件接收的数据添加链接和格式(文本粗体、下划线或增加字体大小)。请找到以下示例 json 文件。
{
"Header": "Sample Header",
"Head": "Click on “Accept” if you consent to the Terms and Conditions listed below or select “Decline” if you do not consent.",
"Description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. It www.google.com was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. \\n **Heading** \\n 1.) It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout."
}
在 js 文件中使用以下代码从 json 文件接收数据。
import terms from "./TermsAndCondition.json";
let desc = terms.Description.replaceAll("\\n", "\n");
尝试使用以下代码添加链接,但它在网页中显示为带有锚标记的文本。
let res = "www.google.com".link("https://www.google.com");
desc = desc.replace("www.google.com", res);
另外我想突出显示 json 文件中的一些单词并将其显示给 UI。
谁能帮我实现同样的目标。
解决方案
推荐阅读
- javascript - 角度点击事件:如何选择元素中的复选框?
- angular - 如果第二次使用角度组件不接收状态数据
- vba - 我的 VBA 访问代码中的 If Else 语句中的语法错误
- autodesk-forge - BIM 查看器标记 - 我们可以编辑保存的标记还是仅支持查看?
- visual-studio - 在 Visual Studio 2017 上调试时将新文件夹添加到解决方案
- python - 为抓取网站找到正确的元素
- python-3.x - 如何以更有效的方式对 ID 进行编码 - 使用密码库
- java - 从复杂的 SQL 查询构建 CriteriaQuery
- usb - STMF32F303 上的复合 USB CDC/HID 设备
- javascript - 将字符串保存到 p5 中的文本文件