开发者

HTML and Javascript: How to manage element focus?

开发者 https://www.devze.com 2023-01-04 04:20 出处:网络
I have some questions about focus in general (adhering to WC3 format, screw IE). I\'m having problems with unintended actions occurring on a widget i am building (using the Dojo Toolkit), and i believ

I have some questions about focus in general (adhering to WC3 format, screw IE). I'm having problems with unintended actions occurring on a widget i am building (using the Dojo Toolkit), and i believe a better general understanding of focus will allow me to solve my problem myself, so here goes:

First of all, which common HTML element are and AREN'T focusable? I've been trying to throw focus around and it works sometimes, and doesnt work other times...

What is the 'highest' level focusable on a page? For instance, can i focus the window? The <body> tag? Specific to dojo, can you focus an entire widget? If the template is widgeted can you focus just highest level of the template (usually a <div>)?

Can focus be 'remove开发者_如何学运维d'? Can i remove focus from all elements/objects on the page until the next object is focused? Can i prevent a element from being focusable (like a button)?

What are all the methods through which i can affect focus? Besides calling the focus() method on elements, can focus be set through HTML attributes or in a CSS?

Thanks in advance for what i hope to be some great answers!


  • Disabled controls can't receive focus according to the HTML4.01 spec

  • Firefocus, an extension that works over Firebug, could be a great enhancement if you're asking this sort of questions :) Install, restart and look at the Console

  • Related to focus is the order in which elements are given the focus, that is the order of tabbing navigation and the tabindex attribute with its values -1, 0 or positive when it exists


  1. Any DOM element can receive focus amongst other some event handlers.
  2. See answer 1.
  3. Focus is passed around and not removed.
  4. Focus can only be set by the DOM using JavaScript.


You can also use dojo.place to put things in the correct for focus.

0

精彩评论

暂无评论...
验证码 换一张
取 消