哪些HTML元素可以接收焦点?我正在寻找一个HTML元素的明确列表,这些元素允许聚焦,也就是说,当focus()被召唤了吗?我正在编写一个jQuery扩展,它工作在可以聚焦的元素上。我希望这个问题的答案将使我能够具体说明我所针对的内容。
3 回答

呼啦一阵风
TA贡献1802条经验 获得超6个赞
focus()
focus()
带有href的HTMLAncementElement/HTMLAreaElement HTMLInputElement/HTMLSelectElement/HTMLTextAreaElement/HTMLButtonElement但不是 disabled
(如果您尝试的话,实际上会给您一个错误),而且文件上传出于安全原因有不寻常的行为。 HTMLIFrameElement(虽然聚焦并没有做任何有用的事情)。其他嵌入元素也可能,我还没有全部测试过。 具有 tabindex

阿波罗的战车
TA贡献1862条经验 获得超6个赞
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 */ }
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 */ }}
编辑:
[contentEditable=true]

慕桂英4014372
TA贡献1871条经验 获得超13个赞
$focusable: 'a[href]', 'area[href]', 'button', 'details', 'input', 'iframe', 'select', 'textarea', // these are actually case sensitive but i'm not listing out all the possible variants '[contentEditable=""]', '[contentEditable="true"]', '[contentEditable="TRUE"]', '[tabindex]:not([tabindex^="-"])', ':not([disabled])';
我改变了 :not([tabindex="-1"])
到 :not([tabindex^="-"])
因为产生 -2
不知何故。安全总比抱歉好对吧? 加法 :not([tabindex^="-"])
对于所有其他可聚焦的选择器来说,都是毫无意义的。使用时 [tabindex]:not([tabindex^="-"])
它已经包含了所有你要否定的元素 :not
!我包括 :not([disabled])
因为禁用元素可以 绝不可能
可聚焦。所以再一次,把它添加到每个元素中是没有用的。
- 3 回答
- 0 关注
- 2558 浏览
相关问题推荐
添加回答
举报
0/150
提交
取消