我想只有在下面的例子中拉出“88”的数字:jQuery的使用nextSibling拔出数据
<li>
<a href="website">5 stars</a>
(88)
</li>
我曾尝试:
var theLi= $('li');
var theNumber = $(theLi.get(0).nextSibling).text();
,但没有出现。它是空白的。
我想只有在下面的例子中拉出“88”的数字:jQuery的使用nextSibling拔出数据
<li>
<a href="website">5 stars</a>
(88)
</li>
我曾尝试:
var theLi= $('li');
var theNumber = $(theLi.get(0).nextSibling).text();
,但没有出现。它是空白的。
怎么样
var theNumber = $('li').after($('a')).text().replace('(','').replace(')','')
这工作。
这同样的事情已经有了答案在另一个线程:Using .text() to retrieve only text not nested in child tags
您克隆里,取出子元素,并提取文本。
Very关闭但括号仍然存在。 – ToddN 2012-02-13 01:03:25
这应该工作,http://jsfiddle.net/elclanrs/bPqDR/:
$('li').clone().children().remove().end().text();
请使用jsFiddle.net在发布之前测试您的答案,以免误导人们。你的方法不起作用:http://jsfiddle.net/Gq3nE/ – nopuck4you 2012-02-13 00:54:59
作品:http://jsfiddle.net/hJemv/1/ – 2012-02-13 01:02:44
非常接近但圆括号仍然保留 – ToddN 2012-02-13 01:03:56