How to implement debounce fn into jQuery keyup event?

前端 未结 1 1105
轮回少年
轮回少年 2020-11-30 08:42

A calculation is based on user input, and criteria is to use keyup rather than change or blur.

The problem is that the code fi

相关标签:
1条回答
  • 2020-11-30 09:18

    Use it like this:-

    $('input').keyup(debounce(function(){
            var $this=$(this);
            //alert( $this.val() );
            var n1 = $this.val();
            var n2 = $('#n2').val();
            var n3 = $('#n3').val();
            var calc = n1 * n2 * n3;
            alert(calc);
        },500));
    

    Fiddle

    0 讨论(0)
提交回复
热议问题