Jak ustawić fokus na elemencie HTML?jquery focus on load
Używam document.getElementById('ID_HTML_wanted').focus();
, ale mój element html "ID_HTML_wanted" jako nie fokus. I użytkownik jquery api .focus
Jak ustawić fokus na elemencie HTML?jquery focus on load
Używam document.getElementById('ID_HTML_wanted').focus();
, ale mój element html "ID_HTML_wanted" jako nie fokus. I użytkownik jquery api .focus
Spróbuj owinąć swój kod do tego kodu, więc wykonuje PO DOM jest gotowy
$(function(){
//your code
});
więc będzie stać
$(function(){
document.getElementById('ID_HTML_wanted').focus();
});
jednak swój element't don” t mieć metodę .focus(), jeśli naprawdę chcesz użyć jQuery jeden, użyj
$(function(){
$("#ID_HTML_wanted").focus();
});
Tak, jestem głupi, nie mam do ustawiania ostrości, gdy DOM jest gotowy: '$ (dokument) .ready (function() {$ (" # ID_HTML_ chciany "). Focus();});' – immobiluser
Sor ry, mam skutecznie pominąć, aby ustawić ostrość, gdy DOM jest gotowy:
$(document).ready(function() {
$("#ID_HTML_wanted").focus();
});
Wszystkie trzy z poniższych składni z .ready() są równoważne:
$(document).ready(handler)
$().ready(handler) (this is not recommended)
$(handler)
Głupi, mam pominąć, aby ustawić ostrość, gdy DOM jest gotowy : $ (dokument) .ready (function() { document.getElementById ('ID_HTML_wanted'). Focus(); }); – immobiluser