関数が機能しないのはなぜですか:
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」に変換