Prevent both blur and keyup events to fire after pressing enter in a textbox

后端 未结 8 427
粉色の甜心
粉色の甜心 2021-01-11 10:13

After pressing enter I would like that only the keyup event be fired but blur is fired first. How to cancel blur when

8条回答
  •  攒了一身酷
    2021-01-11 11:21

    I Couldn't alter class attribute so i'd ended up with,

    $(".textbox").on("blur",function () { 
        if($(this).attr('flag')!='1') 
            alert("blur Event fired");
    });
    
    $(".textbox").on("keyup",function (event) { 
        $(this).attr('flag','1');
        if(event.keyCode == 13){ // Detect Enter
            alert("KeyUp fired after pressing Enter");
        }
        $(this).attr('flag','0');
    });
    

提交回复
热议问题