Hier habe ich einen CSS-Selektor basierend auf bobince ‚s answer jedes fokussierbare HTML-Element zu wählen:
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 */
}
oder ein wenig schöner 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 */
}
}
ich hinzugefügt habe es als Antwort, denn das war, wonach ich gesucht hatte, als Google mich auf diese Stackoverflow-Frage umgeleitet hat.
EDIT: Es gibt einen weiteren Selektor, die fokussierbar ist:
[contentEditable=true]
Dies ist jedoch nur sehr selten verwendet wird.
Jede Idee Wie bekommt man all das mit jQuery? Siehe auch http://stackoverflow.com/questions/7668525/is-there-a-jquery-selector-to-get-all-elements-that-can-get-focus – ripper234
Ich fand einige interessante Ergebnisse: http: // jsfiddle.net/B7gn6/ schlägt mir vor, dass die "tabindex" attrib ist nicht genug, um in Chrome mindestens zu arbeiten .. –
@jon: diese Tabindex-Elemente tatsächlich akzeptieren Fokus, obwohl, wenn Sie versuchen, sie zu klicken. Das Testen von '.is (': focus')' ist nicht zuverlässig - jQuery implementiert einen eigenen Test für ': focus' in Chrome, was Sie hier testen. Dieser jQuery-Code ist unzuverlässig/fehlerhaft ('~ tabIndex' ..?! Das wird nicht funktionieren ...) – bobince