在数字前添加英镑符号

时间:2015-11-27 17:17:37

标签: jquery

我正在添加两个值。计算正确,但我想用英镑符号显示结果。我加上我喜欢这个,但没有工作。

我的HTML是

<td class="#perMonth">&pound 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('&pound;'parseInt(income1));
            } else if(!isNaN(income2 == '') && income1 == '') {
                $perMonth.html('&pound;'parseInt(income2));
                $('#totalIncom').html('&pound;'parseInt(income2));
            } else {
                $perMonth.html('&pound;'parseInt(income1)+'&pound;'parseInt(income2));
                $('#totalIncom').html('&pound;'parseInt(income1)+'&pound;'parseInt(income2));
            }
    });

1 个答案:

答案 0 :(得分:2)

你需要+用于字符串连接:

所以而不是

$('#totalIncome').html('&pound;'parseInt(income1));

你需要

$('#totalIncome').html('&pound;' + parseInt(income1));