“开启模糊”事件首先会提供不同的布尔输出,并且在随后的模糊中,输入值相同的情况也会有所不同

时间:2019-07-06 17:09:42

标签: javascript jquery

我具有以下JavaScript函数,用于检查所选成员是否有一定数量的可用存款并返回布尔值。 当我输入值时,第一个模糊事件会返回意外的布尔值,该值在随后的模糊中会发生变化

<script type="text/javascript">
     window.isQualified = false;

    function check_available_deposit() {


        guarantor_number = $("#guarantor_number").val()
        var amount_entered =parseFloat($("#amount_guaranteed").val());
        console.log(guarantor_number);

        const url = 'http://localhost:1079/loanapplication/check_deposit/?member_number=' + guarantor_number

        $.getJSON(url, function (data) {

            $.each(data, function (key,entry) {

                const free_deposit = parseFloat(JSON.stringify(entry[4].Value))
                console.log(free_deposit)

                if (free_deposit<=0||!free_deposit) {
                    console.log('member '+member_number+' has no  available deposit!')
                    return false;
                }

                if (amount_entered <= free_deposit)  {


                    window.isQualified=true;
                    console.log('no ' + isQualified)

                }
                else {

                     window.isQualified=false;
                    console.log('yes ' +window.isQualified )


                }

            })

        })
        console.log( window.isQualified )
        return window.isQualified 

    }

</script>

这就是我所谓的onblur事件。

<script type="text/javascript">
    $("#amount_guaranteed").on('blur', function () {
        check_available_deposit()

    })


</script>

0 个答案:

没有答案