Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 在数字前添加英镑符号_Jquery - Fatal编程技术网

Jquery 在数字前添加英镑符号

Jquery 在数字前添加英镑符号,jquery,Jquery,我在添加两个值。计算正确,但我想用磅符号显示结果。我补充说我喜欢这个但不工作 我的html是 <td class="#perMonth">&pound 0</td> $('.totalIncome').on('keyup',function(e) { var income1 = $('#monthlyIncome').val(), income2 = $('#otherIncome').val(),

我在添加两个值。计算正确,但我想用磅符号显示结果。我补充说我喜欢这个但不工作

我的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));
            }
    });
英镑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('&pound;'parseInt(income1));
你需要

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

看起来你在一些地方也把“#totalIncome”拼写为“#totalIncom”。