Come impostare lo stato attivo su un elemento html?jquery focus on load
Io uso document.getElementById('ID_HTML_wanted').focus();
ma il mio elemento html "ID_HTML_wanted" non è lo stato attivo. Mi utente jquery api .focus
Come impostare lo stato attivo su un elemento html?jquery focus on load
Io uso document.getElementById('ID_HTML_wanted').focus();
ma il mio elemento html "ID_HTML_wanted" non è lo stato attivo. Mi utente jquery api .focus
Cercate di avvolgere il codice per il codice in modo che viene eseguito dopo DOM è pronto
$(function(){
//your code
});
in modo che diventi
$(function(){
document.getElementById('ID_HTML_wanted').focus();
});
Tuttavia, il vostro element't don' t avere il metodo .focus(), se si desidera REALMENTE utilizzare quello di jQuery, utilizzare
$(function(){
$("#ID_HTML_wanted").focus();
});
Sì, sono stupido, ho omesso di mettere a fuoco quando DOM è pronto: '$ (document) .ready (function() {$ (" # ID_HTML_wanted "). Focus();});' – immobiluser
Sor ry, ho efficacemente omettere impostare fuoco quando DOM è pronto:
$(document).ready(function() {
$("#ID_HTML_wanted").focus();
});
Tutti e tre i seguenti sintassi di .ready() sono equivalenti:
$(document).ready(handler)
$().ready(handler) (this is not recommended)
$(handler)
stupido, ho omettere impostare fuoco quando DOM è pronto : $ (document) .ready (function() { document.getElementById ('ID_HTML_wanted'). Focus(); }); – immobiluser