为什么我的功能不起作用:
HTML:
<div class="cash">1234.00</div>
<div class="cash">123456.00</div>
<div id="total"></div>
JS:
function formatPrice(price) {
return price.reverse().replace(/((?:\d{2})\d)/g, '$1 ').reverse();
}
// Need to extend String prototype for convinience
String.prototype.reverse = function() {
return this.split('').reverse().join('');
}
$('.cash').each(function(){
$(this).html().formatPrice().appendTo('body');
});
我也试过这个,没有运气:
$('.cash').each(function(){
$(this).html() = i;
formatPrice(i).appendTo('body');
});
即使将其剥离为基本功能,它仍然不会附加我的东西......我失去了我的魔力吗?
$('.cash').each(function(){
$(this).html().appendTo('body');
});
谢谢
更新:该功能只是假设这样做:
formatPrice('1234.00') //转换为“1 234.00” formatPrice('123456.00') //转换为“123 456.00”