简体   繁体   中英

iOS input focus on tap

As you know there is 300ms delay on iOS "click" event, that's why mobile developers use different libraries to achieve "tap" event with no delay (I use tap.js). BUT when you tap/click on <input type="text" /> element there is still 300ms delay before focus. So, does anybody know how to make input focused on tap, not on click?

You have to manually disable native behavior and force the focus event

Example:

$('input').on('touchstart', function(e){
     e.preventDefault();
     e.stopPropagation();
     $(this).trigger('focus');
});

That's it.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM