我正在添加两个值。计算正确,但我想用英镑符号显示结果。我加上我喜欢这个,但没有工作。
我的HTML是
<td class="#perMonth">£ 0</td>
$('.totalIncome').on('keyup',function(e) {
var income1 = $('#monthlyIncome').val(),
income2 = $('#otherIncome').val(),
$perMonth = $('#perMonth');
if(income1 == '' && income2 == '') {
$perMonth.html(0);
} else if(!isNaN(income1 == '') && income2 == '') {
$perMonth.html(parseInt(income1));
$('#totalIncom').html('£'parseInt(income1));
} else if(!isNaN(income2 == '') && income1 == '') {
$perMonth.html('£'parseInt(income2));
$('#totalIncom').html('£'parseInt(income2));
} else {
$perMonth.html('£'parseInt(income1)+'£'parseInt(income2));
$('#totalIncom').html('£'parseInt(income1)+'£'parseInt(income2));
}
});
答案 0 :(得分:2)
你需要+用于字符串连接:
所以而不是
$('#totalIncome').html('£'parseInt(income1));
你需要
$('#totalIncome').html('£' + parseInt(income1));