how to prevent blur() running when clicking a link in jQuery?

前端 未结 4 1403
死守一世寂寞
死守一世寂寞 2020-11-27 07:12

i have:


and

$(\'input\').blur(function(){
    alert(\'stay focused!\');
});

4条回答
  •  难免孤独
    2020-11-27 07:20

    Delay the blur a bit. If the viewer clicks a link to another page, the page should change before this code gets a chance to run:

    $('input').blur(function(){
        setTimeout(function() {alert('stay focused!');}, 1000);
    });
    

    You can experiment with what delay value for the timeout seems appropriate.

提交回复
热议问题