admin管理员组文章数量:1022525
How does one in iOS (iPad/iPhone/iPod) to force the focus on an input element when the DOM is ready, with jQuery?
I've got a barcode webpage, that needs the focus to be immediately on a textfield.
I've found jQuery will do just fine for IE,Firefox,Chrome,Safari,Android but iOS mobile Safari, and iOS mobile Chrome won't let me focus on a textfield when the DOM is ready.
This is what I have so far:
$j(document).ready(function() {
$j('#barcode').focus();
});
Any ideas, guys/gals?
How does one in iOS (iPad/iPhone/iPod) to force the focus on an input element when the DOM is ready, with jQuery?
I've got a barcode webpage, that needs the focus to be immediately on a textfield.
I've found jQuery will do just fine for IE,Firefox,Chrome,Safari,Android but iOS mobile Safari, and iOS mobile Chrome won't let me focus on a textfield when the DOM is ready.
This is what I have so far:
$j(document).ready(function() {
$j('#barcode').focus();
});
Any ideas, guys/gals?
Share Improve this question edited Aug 30, 2013 at 5:15 rink.attendant.6 46.5k64 gold badges110 silver badges157 bronze badges asked Aug 29, 2013 at 19:46 user2730049user2730049 111 silver badge3 bronze badges 1-
Nothing to show - all the code is thus:
$j(document).ready(function() { $j('#barcode').focus(); });
– user2730049 Commented Aug 29, 2013 at 20:44
1 Answer
Reset to default 4It is not possible on Mobile Safari and presumably Chrome on iOS. See the following duplicate SO questions:
How do I focus an HTML text field on an iPhone (causing the keyboard to e up)?
Mobile Safari: Javascript focus() method on inputfield only works with click
Running this fiddle in Mobile Safari or Chrome on iOS will confirm this answer.
$("input").focus(); // Does not focus input in Mobile Safari or Chrome on iOS.
This code has been tested (and failed) in Mobile Safari and Chrome on iOS on the following devices:
- iPhone 4 running iOS 7 beta 6
- iPad 2 running iOS 6.1.3
- iOS Simulator running iOS 7 beta 5
How does one in iOS (iPad/iPhone/iPod) to force the focus on an input element when the DOM is ready, with jQuery?
I've got a barcode webpage, that needs the focus to be immediately on a textfield.
I've found jQuery will do just fine for IE,Firefox,Chrome,Safari,Android but iOS mobile Safari, and iOS mobile Chrome won't let me focus on a textfield when the DOM is ready.
This is what I have so far:
$j(document).ready(function() {
$j('#barcode').focus();
});
Any ideas, guys/gals?
How does one in iOS (iPad/iPhone/iPod) to force the focus on an input element when the DOM is ready, with jQuery?
I've got a barcode webpage, that needs the focus to be immediately on a textfield.
I've found jQuery will do just fine for IE,Firefox,Chrome,Safari,Android but iOS mobile Safari, and iOS mobile Chrome won't let me focus on a textfield when the DOM is ready.
This is what I have so far:
$j(document).ready(function() {
$j('#barcode').focus();
});
Any ideas, guys/gals?
Share Improve this question edited Aug 30, 2013 at 5:15 rink.attendant.6 46.5k64 gold badges110 silver badges157 bronze badges asked Aug 29, 2013 at 19:46 user2730049user2730049 111 silver badge3 bronze badges 1-
Nothing to show - all the code is thus:
$j(document).ready(function() { $j('#barcode').focus(); });
– user2730049 Commented Aug 29, 2013 at 20:44
1 Answer
Reset to default 4It is not possible on Mobile Safari and presumably Chrome on iOS. See the following duplicate SO questions:
How do I focus an HTML text field on an iPhone (causing the keyboard to e up)?
Mobile Safari: Javascript focus() method on inputfield only works with click
Running this fiddle in Mobile Safari or Chrome on iOS will confirm this answer.
$("input").focus(); // Does not focus input in Mobile Safari or Chrome on iOS.
This code has been tested (and failed) in Mobile Safari and Chrome on iOS on the following devices:
- iPhone 4 running iOS 7 beta 6
- iPad 2 running iOS 6.1.3
- iOS Simulator running iOS 7 beta 5
本文标签: javascriptHow do I force focus on a texfield when the DOM is ready in iOSStack Overflow
版权声明:本文标题:javascript - How do I force focus on a texfield when the DOM is ready in iOS? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745566847a2156501.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论