我想匹配两个浮点数,但无法检查以下内容:

https://jsfiddle.net/mcsab3aa/2/

js代码:

$('#checkButton').click(function() {
    var getusertarget = parseFloat(jQuery("#targetval").val());
    var currentval = $("#demo").find( "h1" ).html();
    currentval = parseFloat(currentval.replace('$',''));
    console.log(currentval);
    console.log(getusertarget);
    var dividerval = (currentval/targetval);  // it should be 1
    console.log(dividerval);
    if (dividerval==1) {
        $('.coins_drags').hide();
        //$("#demo").find( "h1" ).html('$' + sum.toFixed(2) + '<br />Great job');
        console.log('great');
 }
    else {
        //$("#demo").find( "h1" ).html('$' + sum.toFixed(2) + '<br />Try again');
        //sum = 0;
        console.log('try');
    }

});

最佳答案

var dividerval = (currentval/targetval);


targetval是未定义的。您可能想要做:

var dividerval = (currentval/getusertarget);

10-07 17:13