简体   繁体   English

AJAX和辅助功能:活动元素上的焦点或制表符索引

[英]AJAX and accessibility: focus or tab index on active element

I am currently developing an AJAX application which has to be accessible (WGAG 2.0, AA). 我目前正在开发一个必须可访问的AJAX应用程序(WGAG 2.0,AA)。

I am testing my application with a screen reader (Voice Over for now, on Mac Os X). 我正在使用屏幕阅读器测试我的应用程序(目前,在Mac Os X上使用Voice Over)。

The navigations consists of a series of buttons. 导航由一系列按钮组成。 When the user click on a button, the javascript check if the content has been added to the page, if not, it performs an AJAX call, append a new div to the page, hide previous elements and display the new content, which works fine. 当用户单击按钮时,javascript检查内容是否已添加到页面中,如果没有,则执行AJAX调用,向页面添加新div,隐藏以前的元素并显示新内容,哪个工作正常。

The issue I have is I want the user to go directly to the content when the button has been pressed, so the person can read the content directly instead of leaving the cursor at the button (so for now, when the client press the button, the cursor stay on the button, instead of reading the content that has been loader). 我的问题是我希望用户在按下按钮时直接转到内容,这样人就可以直接读取内容而不是将光标留在按钮上(所以现在,当客户端按下按钮时,光标停留在按钮上,而不是读取已加载的内容)。

I tried: 我试过了:

$(id).attr("tabindex",-1).focus();

and

$(id).focus();

where id is the variable that contains the id value (with the right selector '#'). 其中id是包含id值的变量(使用右选择器'#')。

It does not work very well, I think this is because at the second click on a button, two elements have the tabindex set to -1, but I am not sure. 它不能很好地工作,我认为这是因为在第二次单击按钮时,两个元素的tabindex设置为-1,但我不确定。

I am wondering if someone know which approach I should use ? 我想知道是否有人知道我应该使用哪种方法?

UPDATE ** 更新**

There are 2 places in the same page (AJAX application) where I need the feature, the first part is a widget where setting tabindex to -1 works just fine: 在我需要该功能的同一页面(AJAX应用程序)中有2个位置,第一部分是将tabindex设置为-1的小部件可以正常工作:

PLACE I 地点我

html HTML

<div id="audience-list" class="with-shadow">
    <div id="group-links">
        <div id="confirm-dialog" class="toolBar">
            <button id="cancelBtn">
                Cancel
            </button>
            <button value="group-1" class="highlighted" id="confirmBtn">
                Confirm
            </button>
        </div>
        <div class="d4p-no-ajax group-link selected">
            <div class="span-4 prepend-top">
                <div class="box square with-outset with-large-radius">
                    <div id="apuo" role="button" class="choose-group-button">
                        <h2>My group</h2>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

javascript (from what I learnt yesterday, I should replace the click function by on, will do it, but now this is working just fine). javascript(从我昨天学到的东西,我应该用on替换点击功能,会做到这一点,但现在这个工作正常)。 When the user click on the button, he is send to the div that holds the buttons cancel and confirm. 当用户点击按钮时,他被发送到保持按钮取消和确认的div。 This works just fine! 这很好用!

$(".choose-group-button").click(function(e){

    $('#confirm-dialog').addClass('enabled').attr("tabindex",-1).focus();

});

PLACE II, just do not work PLACE II,只是不工作

html: I tried different scenarios with links and buttons with no more chance. HTML:我尝试了不同的方案,链接和按钮没有更多的机会。 When you click on a link or a button, you should tabindex to the div referenced in the href (here is the dom content, the anchors are modified #avantages -> #/avantages has been modified) or to the div with ID content-container 当您单击链接或按钮时,您应该tabindex到href中引用的div(这里是dom内容,修改了锚点#avantages - >#/ avantages已被修改)或者ID为div的div-容器

<div>

    <div id="ico-avantages" class="box box-ico square">
        <span class="ico"></span>
        <a id="d4p-link15" href="#/avantages">
            Avantages sociaux 
        </a>
    </div>

    ...

    <div class="clear">
    </div>
</div>
<div id="content-container">
    <div id="avantages">
    ...
    </div>
    ...
</div>

JAVASCRIPT JAVASCRIPT

$('.box-ico a').each(function(){
    $(this).click(function(){
        $('#content-container').attr('tabindex', -1).focus();     
    });
});

The tabindex is set to -1, the screen scroll to the div, but the screen reader in this case stay at the link level whereas in place 1 on the same page, it works just fine. tabindex设置为-1,屏幕滚动到div,但是在这种情况下屏幕阅读器保持在链接级别,而在同一页面上的位置1,它工作得很好。 I am wondering now if there are some more specific conditions that must apply for a div in order to receive focus. 我现在想知道是否有一些更具体的条件必须适用于div以获得焦点。

Tabindex 0 and -1 have a different behavior than positive intergers. Tabindex 0和-1具有与正整数不同的行为。 Snook's post about tabindex may help some. Snook关于tabindex的帖子可能有所帮助。 Multiple elements on a page can contain a tabindex="-1" . 页面上的多个元素可以包含tabindex="-1" I am not an expert in <buttons> , but typically they are for form submission versus navigation, so my first suggestion would be making the buttons into normal links. 我不是<buttons>的专家,但通常它们用于表单提交和导航,因此我的第一个建议是将按钮设置为普通链接。

<a href="#myID">Jump to Section name</a>
...
<div id="myID" tabindex="-1">
...
</div>

You may need to do another trick 你可能需要做另一个技巧

<a href="#myID">Jump to Section name</a>
...
<div>
 <a name="myID" id="myID" tabindex="-1"></a>
...
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM