[英]JQuery focus and click running on same time on element
I have a button which has 2 different behaviors 我有一个具有2种不同行为的按钮
Case 1 is working fine, but when we hit enter key the focus moves to Button 2 and then moving to button 1, Here I found blur also calling when we hit the enter button so it calling the concern function, is there any way to achieve my goal? 情况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);
});
Update your jquery Like this 像这样更新你的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.