簡體   English   中英

jQuery焦點並單擊在元素上同時運行

[英]JQuery focus and click running on same time on element

我有一個具有2種不同行為的按鈕

  1. 使用Tab鍵在鍵盤上導航時,當按鈕模糊時,應將焦點移至按鈕1
  2. 當我們按下回車鍵時,它應該將焦點移至按鈕2

情況1運行正常,但是當我們按Enter鍵時,焦點移至Button 2,然后移至Button 1,在這里我發現當我們按Enter鍵時也調用了模糊,因此它調用了關注功能,有什么方法可以實現我的目標?

$('#btn').on('focus', function(){
    }).on('blur', function(){
         setTimeout(function() {
            $('.span-hlo')[0].focus(); 
        },250);
});
$('#btn').on('click', function(){
setTimeout(function() {
    $('.span-welcome')[0].focus(); 
  },250);
});

小提琴的例子

像這樣更新你的jquery

var lastClick = null;
$('#btn').mousedown(function(e) {
  lastClick = e.target;
}).focus(function(e){
    if (e.target == lastClick) {
      $('.span-welcome')[0].focus(); 
    } else {
      $('.span-hlo')[0].focus();    
    }
    lastClick = null;

});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM