$(document).ready(function () {
$(document).on('body', function () {
var visibleInput = $("input[type=text]").filter(':visible');
visibleInput.focus();
});
});
it doesn't work this way I wonder why. No error in the console.
Try this
$(document).ready(function(){
$("input[type=text]").filter(':visible').focus();
});
I think there no body events in either JQuery or javascript. Normally you can't focus multiple elements at a time so use second one else it will focus on last textinput only.
$(document).ready(function(){
var visibleInput = $("input[type=text]").filter(':visible');
visibleInput.focus(); //Focus last textinput with visible not first one.
});
If you want focus first textinput with visible try this one
$("input[type=text]").filter(':visible').first().focus();
How many inputs are there on the page?
Only one input can have focus at a time... I would assume that that variable declaration would pick up each input.
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.