My question is simple let's say you have multiple <span>
elements like this
<span class="hi">10,000</span>
<span class="hi">20,000</span>
<span class="hi">40,000</span>
<span class="hi">500,000</span>
How do you get each number content inside the span tag, strip the commas away and add the numbers get the answer and add commas, cause I can't seem to figure out a way to do this.
This is what I want to achieve
//data would be gotten from Span tag with class HI
<script>
var addthevalue = 10000+20000+40000+500000;
$(#theans).html(addthevalue);
</script>
<div id=theans></div>
var total = 0;
$(".hi").each(function() {
total += parseInt($(this).html().replace(",", ""));
});
$("#theans").html(total);
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加