0

我正在使用 HTML/JS 开发 Windows 8 应用程序。我们有一个 WinJS.UI.ToggleSwitch 元素,并希望在其上设置 accesskey 属性以进行键盘导航。

<div data-win-control="WinJS.UI.ToggleSwitch"></div>

看起来它最终以具有多个元素的嵌套 div 结构结束。使用 DOM 资源管理器,实际的控件如下所示:

<input class="win-switch" role="checkbox" aria-checked="false" aria-disabled="false" aria-labelledby="ms__id77" type="range" max="1" step="1"></input>

我可以在 DOM 资源管理器中向这个 div 添加一个 accesskey 属性,它可以工作。我的问题是如何将它添加到原始标记中的控件中?

4

1 回答 1

0

Looking at the implementation of this control, it's going to be hard. I see you have two options:

  1. In the code that constructs this control, do the "unpleasant" thing, and querySelector for the element, and set it yourself.
  2. Derive from WinJS.UI.ToggleSwitch, and monkey patch _setElement, to allow you to do it yourself after the fact.

Both of these are highly subject to changes in future versions, with 2 being the most likely to break since you are monkey patching in an internal method.

于 2012-11-26T17:15:09.847 回答