php - 为什么这个 jQuery Replace() 不能在 <a 标签中工作,尽管我让它在 <p 标签中工作?

标签 php javascript jquery html

代码位于@ http://www.iluvtrees.org/我们正在尝试删除冒号 (:)...

jQuery('#events-calendar-list li a').text(this.text().replace(':', ''));

我正在远程执行此操作,并且能够使用此脚本获得更简单的字符串来工作。选择器的困难,我们的 html 看起来像这样......

...
<ul id="events-calendar-list">
<li id="events-calendar-list-630" title="
<strong>Title: </strong><b>#62 It's Little Things
</b><br />Check your fuel consumption and tire pressure to make sure your car is running as efficiently as possible.
<br /><strong>Start Time: </strong>12:00 am<br /><strong>End Time: </strong>12:00 am<br />">events=Object { mouseover=[1]}handle=function()
<a href="http://www.iluvtrees.org/">
<strong style="display: none;">Thu 3/14/2013</strong>
: //<- - - this is what we are trying to remove - - - -
<b>#62 It's Little Things</b>
<br>
</a>
...

我目前无权访问 PHP 文件以从那里删除。

最佳答案

您可以简单地删除 anchor 内的文本节点:

$('a').contents().filter(function(node) {
  return this.nodeType === 3; // filter text nodes
}).remove();

Demo

关于php - 为什么这个 jQuery Replace() 不能在 <a 标签中工作,尽管我让它在 <p 标签中工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15424208/

相关文章:

php - 检索特定行的 SQL 问题

javascript - 从 Javascript 调用 php 函数的最简单方法是什么?

php - 如何在没有 SSL 的情况下保护身份验证 cookie

javascript - 将 Javascript 对象转换为 jquery 对象?

javascript - 使用本地存储保存和加载输入值?

javascript - 在 React JavaScript 中显示/映射嵌套 JSON 字段

javascript - 将 Div ID 添加到 YouTube iFrame

javascript - 使用 google chrome 扩展在 facebook 帖子中添加额外按钮

javascript - 如何使用jquery渐进修改Translate

jquery - Google map 标记选择