jquery 如何把两个span里的值加在一起 求大神
<divclass=".vv">¥<spanclass="sp0">100,000,000.00</span><spanclass="sp1">300,000,000.0...
<div class=".vv">
¥<span class="sp0">100,000,000.00</span>
<span class="sp1">300,000,000.00</span>
</div>求把两个span值加一起得到400,000,000.00 展开
¥<span class="sp0">100,000,000.00</span>
<span class="sp1">300,000,000.00</span>
</div>求把两个span值加一起得到400,000,000.00 展开
展开全部
Math.format = function (number, style) {
var split,
intLen,
declen;
if (/^#+([^#.]+)(#+)(?:\.(#+))?$/.test(style)) {
//分割符
split = RegExp.$1;
intLen = RegExp.$2.length;
declen = RegExp.$3.length;
}else if(/^(#+)(?:\.(#+))?$/.test(style)){
split = '';
intLen = RegExp.$1.length;
declen = RegExp.$2.length;
}else{
return number;
}
//保留小数位数
number = parseFloat(number).toFixed(declen);
var re = new RegExp('(\\d{1,' + intLen + '})(?=(\\d{' + intLen + '})+(?:$|\\.))', 'g');
//console.log(re);
if(!/(-?\d+)(?:\.(\d+))?/.test(number)){
return;
}
var d = (RegExp.$2 ? '.' + RegExp.$2 : ''),
str = RegExp.$1.replace(re, function (a, b, c, d) {
return b + split;
});
return str + d;
};
$(function(){
var total = 0;
$('span').each(function(){
total += parseFloat($(this).html().replace(/,/g,''));
});
console.log(Math.format(total,'#,###.##'));
});
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询