Qui ho un CSS selettore sulla base di bobince s' answer per selezionare qualsiasi elemento attivabile HTML:
a[href]:not([tabindex='-1']),
area[href]:not([tabindex='-1']),
input:not([disabled]):not([tabindex='-1']),
select:not([disabled]):not([tabindex='-1']),
textarea:not([disabled]):not([tabindex='-1']),
button:not([disabled]):not([tabindex='-1']),
iframe:not([tabindex='-1']),
[tabindex]:not([tabindex='-1']),
[contentEditable=true]:not([tabindex='-1'])
{
/* your CSS for focusable elements goes here */
}
o un po' più bello in SASS:
a[href],
area[href],
input:not([disabled]),
select:not([disabled]),
textarea:not([disabled]),
button:not([disabled]),
iframe,
[tabindex],
[contentEditable=true]
{
&:not([tabindex='-1'])
{
/* your SCSS for focusable elements goes here */
}
}
ho aggiunto era una risposta, perché era quello che stavo cercando, quando Google mi ha reindirizzato a questa domanda StackOverflow.
EDIT: C'è un altro selettore, che è attivabile:
[contentEditable=true]
Tuttavia, questo è usato molto raramente.
Qualsiasi idea come ottenere tutto questo con jQuery? Vedi anche http://stackoverflow.com/questions/7668525/is-there-a-jquery-selector-to-get-all-elements-that-can-get-focus – ripper234
Ho trovato alcuni risultati interessanti: http: // jsfiddle.net/B7gn6/ mi suggerisce che l'attributo "tabindex" non è sufficiente per funzionare in Chrome almeno .. –
@jon: quegli elementi tabindex effettivamente accettano l'attivazione, tuttavia, se provi a fare clic su di essi. Il test '.is (': focus')' non è affidabile - jQuery implementa il proprio test per ': focus' su Chrome, che è quello che stai testando qui. Quel codice jQuery è inaffidabile/buggato ('~ tabIndex' ..?!) Non funzionerà ...) – bobince