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

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

<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]),将其剪切,然后将其附加在包裹在中的标记内。

所以这就是我的追求:

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


再说一次,如果有人有什么想法...谢谢!

最佳答案

尝试这个

Demo here

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

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

});

关于jquery - jQuery在元素后获取带有通配符内容的文本并将其移动,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1219359/

10-13 01:54