Jquery 在数字前添加英镑符号
我在添加两个值。计算正确,但我想用磅符号显示结果。我补充说我喜欢这个但不工作 我的html是Jquery 在数字前添加英镑符号,jquery,Jquery,我在添加两个值。计算正确,但我想用磅符号显示结果。我补充说我喜欢这个但不工作 我的html是 <td class="#perMonth">£ 0</td> $('.totalIncome').on('keyup',function(e) { var income1 = $('#monthlyIncome').val(), income2 = $('#otherIncome').val(),
<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
$('totalIncome')。在('keyup',函数(e)上{
var income1=$(“#月收入”).val(),
income2=$(“#其他收入”).val(),
$perMonth=$(“#perMonth”);
如果(income1=''&&income2=''){
$perMonth.html(0);
}如果(!isNaN(income1='')和&income2=''),则为else{
$perMonth.html(parseInt(income1));
$('#totalIncom').html('£;'parseInt(income1));
}如果(!isNaN(income2='')和&income1=''),则为else{
$perMonth.html('£;'parseInt(income2));
$('#totalIncom').html('£;'parseInt(income2));
}否则{
$perMonth.html('£;'parseInt(income1)+'£;'parseInt(income2));
$('#totalIncom').html('£;'parseInt(income1)+'£;'parseInt(income2));
}
});
您需要+进行字符串连接:
所以不是
$('#totalIncome').html('£'parseInt(income1));
你需要
$('#totalIncome').html('£' + parseInt(income1));
看起来你在一些地方也把“#totalIncome”拼写为“#totalIncom”。