Attributo di messa a fuoco automatica HTML
Definizione e utilizzo
L'
autofocus
attributo è un attributo booleano.
Quando presente, specifica che l'elemento deve essere automaticamente attivato quando viene caricata la pagina.
Si applica a
L'
autofocus
attributo può essere utilizzato sui seguenti elementi:
Elementi | Attributo |
---|---|
<pulsante> | messa a fuoco automatica |
<immissione> | messa a fuoco automatica |
<seleziona> | messa a fuoco automatica |
<area di testo> | messa a fuoco automatica |
Esempi
Esempio di pulsante
Un pulsante con autofocus:
<button type="button" autofocus>Click Me!</button>
Esempio di input
Lascia che il campo di input "Nome" si attivi automaticamente quando la pagina viene caricata:
<form action="/action_page.php">
First name: <input type="text" name="fname" autofocus><br>
Last name: <input type="text" name="lname"><br>
<input type="submit">
</form>
Esempio di area di testo
Un'area di testo con messa a fuoco automatica:
<textarea autofocus>
At w3schools.com you will learn how to make a website. We offer free tutorials in all web development technologies.
</textarea>
Supporto browser
L' autofocus
attributo ha il seguente supporto del browser per ogni elemento:
Element | |||||
---|---|---|---|---|---|
form | 5.0 | 10.0 | 4.0 | 5.0 | 9.6 |
input | 5.0 | 10.0 | 4.0 | 5.0 | 9.6 |
textarea | Yes | 10.0 | 4.0 | Yes | Yes |