gpt4 book ai didi

javascript - 从 underscore.js 的模板中删除 html 元素

转载 作者:行者123 更新时间:2023-11-28 08:30:55 25 4
gpt4 key购买 nike

我的 JSON 响应是这样的:

{
"description": "discription about the feaure will come here. <a href=\"http://example.com\" target=\"_blank\">Learn more</a>",
"largeIconURL": "some_path/ico_someicon.gif",
"displayName": "feature one"
},
{
"description": "discription about the feaure will come here.",
"largeIconURL": "some_path/ico_someicon.gif",
"displayName": "feature two"
},
{
"description": "discription about the feaure will come here. ",
"largeIconURL": "some_path/ico_someicon.gif",
"displayName": "feature three"
},

我的模板是这样的

<%
_.each(items,function(item, key, list){
%>
<li>
<div class="oneSpec">

<div class="description">
<h4><%= item.displayName %></h4>
<p><%= item.description %></p>
</div>
</div>
</li>

<%
});
%>

如何在将其绘制到 DOM 之前从 description 节点中删除 anchor 标记

最佳答案

我不完全确定“来自描述”是什么意思,但您可以使用 <% if (condition) {%> 有条件地包含某些内容。我只是猜测你的意思。如果不是这样,你就得更清楚了……

更新:

像这样删除 anchor (Regex in Javascript to remove links):

<%=item.description.replace(/<a\b[^>]*>(.*?)<\/a>/i,"")) %>

关于javascript - 从 underscore.js 的模板中删除 html 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21878532/

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