我认为这可能是一个棘手的问题,但如果有人能解决这个问题,我会非常感动,也非常感激。

这是现有的标记(我无法更改,否则它将是一个简单的问题,我可以自己解决!)

<a title="1 topics" href="http://localhost/tags/amis/">amis</a> (1) 
<a title="2 topics" href="http://localhost/tags/amis/">amis</a> (2) 
<a title="1 topics" href="http://localhost/tags/amis/">amis</a> (1) 
<a title="3 topics" href="http://localhost/tags/amis/">amis</a> (3) 

我想要做的是抓住括号和里面的值([WILDCARD VALUE HERE]),剪切它,然后将它追加到<!> lt;一个<!> gt;标签包裹在<!> lt; span <!> gt;。

所以这就是我所追求的目标:

<a title="1 topics" href="http://localhost/tags/amis/">amis <span>(1)</span></a>

再次,如果有人有任何想法......谢谢!

有帮助吗?

解决方案

试试这个

在此进行演示

$('a').each( function(){

   var $this = $(this);
   var textEl = this.nextSibling;
   var spanEl = $('<span />').text(textEl.data);
   $this.append( spanEl );
   $(textEl).remove();

});
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top