我在 WordPress 网站上有一个标题列表,后面是来源归属、日期和摘录。我想保留标题、来源归属和日期,但想删除日期中“上午”或“下午”之后的所有内容(摘录)。有办法吗?
示例:
NBA 总决赛:勇士队将再次面对骑士队
今日美国 – NBA | 2018 年 5 月 29 日 5:39 am Sports Pulse:《今日美国体育》的萨姆·阿米克详细介绍了勇士队战胜火箭队的第 7 场比赛,以及他们将如何连续第四场比赛。
包含内容的 HTML:
<div class="entry-content cf" itemprop="text">
<div class="entry-excerpt">
<p>
Boston Herald – Boston Celtics | May 29, 2018 8:47 am Here we go again. And again. And, well, again. Round 4 — as many predicted, and others probably lamented — is happening. Cleveland and Golden
</p>
</div>
</div>
最佳答案
假设您正在使用 jQuery。 https://jsfiddle.net/andreitodorut/t4fvqoyw/
$(document).ready(function() {
$('.title').each(function() {
$(this).text(
$(this).text().substr(0,
$(this).text().indexOf(" am") > -1 ?
$(this).text().indexOf(" am") + 3 :
$(this).text().indexOf(" pm") + 3)
)
})
});
关于jquery - 如何删除网页上特定字符之前或之后的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50580099/