以下HTML
<div class="commentlinks">
<a class="commentlinked blogcount">3</a>
<a class="commentlinked fbcount">2</a>
<a class="commentlinked disqcount">1</a>
<a class="allcommentcount"></a>
</div>
使用此jQuery
$('.commentlinks').each(function() {
var currentValue = parseInt($(".blogcount").text());
var currentValue2 = parseInt($(".fbcount").text());
var currentValue3 = parseInt($(".disqcount").text());
var newValue = currentValue + currentValue2 + currentValue3;
$(".allcommentcount").text(newValue);
});
成功返回http://jsfiddle.net/hQzZQ/22/
3 2 1 6但是当我有这个HTML
时<div class="commentlinks">
<a class="commentlinked blogcount">3</a>
<a class="commentlinked fbcount">2</a>
<a class="commentlinked disqcount">1</a>
<a class="allcommentcount"></a>
</div>
<div class="commentlinks">
<a class="commentlinked blogcount">7</a>
<a class="commentlinked fbcount">6</a>
<a class="commentlinked disqcount">1</a>
<a class="allcommentcount"></a>
</div>
它返回http://jsfiddle.net/hQzZQ/23/
3 2 1 74 7 6 1 74
为什么它返回它不正确帮我解决它!
答案 0 :(得分:0)
$('.commentlinks').each(function() {
var currentValue = parseInt($(".blogcount",this).text());
var currentValue2 = parseInt($(".fbcount",this).text());
var currentValue3 = parseInt($(".disqcount",this).text());
var newValue = currentValue + currentValue2 + currentValue3;
$(".allcommentcount",this).text(newValue);
});