开发者

OnClick and OnKeyPress for standards compliance

I am working on a large website (1600+ pages) that needs upgrading to pass standards compliance. As a result, for every OnClick there has to be, say the Standards, an OnKeyPress handler, so that people not using a mouse can still access the content.

Some tags have an onclick javascript handler. EG:

<a onclick="doSumat();">

Is the following cross browser, working javascript:

<a onclick="doSu开发者_开发百科mat();" onkeypress="this.onclick();" >

Will it work reliably in all browsers and will the result be the same as a mouse click for someone using a screen reader?


W3C - SCR35: Making actions keyboard accessible by using the onclick event of anchors and buttons.

While "onclick" sounds like it is tied to the mouse, the onclick event is actually mapped to the default action of a link or button. The default action occurs when the user clicks the element with a mouse, but it also occurs when the user focuses the element and hits enter or space, and when the element is triggered via the accessibility API.

Source http://www.w3.org/TR/WCAG20-TECHS/SCR35


In this case, why not call doSumat(); with both the onclick and onkeypress handlers?

If you need a this context, then you'll need to use doSumat.call(this);, but you can still place that in both handlers.

<a onclick="doSumat();" onkeypress="doSumat();">

With 1600 pages, I imagine you're trying to find something simple to append to every element with an onclick handler, but shouldn't be that much more complex to define rules to blindly copy everything from an onclick statement to an onkeypress expression.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜