I have a button which has 2 different behaviors
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?
$('#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
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;
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.