0

我是社区的新手,我试图在一个简单的数学运算中将点替换为逗号,我真的需要帮助。非常感谢大家。

像这样:jQuery Replace dot to comma and round it

$('#kilometros').keyup(function() { 
   var kilometros = parseFloat($(this).val());
   var precioKilometros = parseFloat($('#precioKilometros').val());
   var totalKilometros = $('#totalKilometros').html((kilometros * precioKilometros));   
     totalKilometros.replace(".", ",");

});

4

2 回答 2

1

$('#totalKilometros').html(...)返回一个没有replace方法的 jQuery 对象。

改为这样做:

var totalKilometros = (kilometros * precioKilometros).toString().replace('.', ',');
$('#totalKilometros').html(totalKilometros);
于 2013-05-10T01:59:07.430 回答
0
$('#kilometros').keyup(function() { 
var kilometros = parseFloat($(this).val());
var precioKilometros = parseFloat($('#precioKilometros').val());
var totalKilometros = kilometros * precioKilometros;
totalKilometros=totalKilometros.replace(".", ",");
$('#totalKilometros').html(totalKilometros);  
});
于 2013-05-10T02:00:03.407 回答