【发布时间】:2014-05-05 11:49:43
【问题描述】:
我使用 focusable 属性来强制 SVG 元素在 HTML 文档中获得焦点。
我需要通过 TAB 键在 SVG 标记中导航 SVG 元素。就像文档中提到的(http://www.w3.org/TR/SVGTiny12/interact.html#focusable-attr)
但我做不到。我已将每个元素的focusable 属性设置为true,并将每个元素的tabindex 设置为0。
这是我的代码:
<div style="border: solid yellow 2px;" tabindex="0">
<svg tabindex="0" width="900px" height="500px" viewBox="0 0 95 50" style="border: solid red 1px;" focusable="true"
xmlns="http://www.w3.org/2000/svg">
<g data-Name="group" tabindex="0" stroke="green" fill="white" stroke-width="5" data-tabindex="0" style="border: solid green 1px;" focusable="true">
<circle tabindex="0" cx="20" cy="25" r="5" focusable="true" data-Name="shape 1" data-tabindex="0" />
<circle tabindex="0" cx="40" cy="25" r="5" focusable="true" data-Name="shape 2" data-tabindex="0" />
<circle tabindex="0" cx="60" cy="25" r="5" focusable="true" data-Name="shape 3" data-tabindex="0" />
<circle tabindex="0" cx="80" cy="25" r="5" focusable="true" data-Name="shape 4" data-tabindex="0" />
</g>
</svg>
我已经在 Google Chrome 中测试了代码。有什么方法可以达到目的吗?
【问题讨论】:
-
大多数浏览器(包括 Chrome)一般只实现 SVG 1.1。 SVG 1.1 没有可聚焦的功能,但 SVG 2 即将推出,浏览器将瞄准它,它将具有可聚焦的(或一些等效的替代方案)
-
@RobertLongson:谢谢。
标签: javascript jquery html svg