简体   繁体   English

屏幕阅读器,即当单击按钮时更改文本时,JAWS无法读取按钮的文本吗?

[英]Screen reader i.e. JAWS doesn't read text of a button when text is changed on click of that button?

I am facing one minor difficulty while making my software ARIA accessibility enabled. 使我的软件ARIA辅助功能启用时,我面临一个小困难。 Any kind of help would be appreciated! 任何帮助将不胜感激!

I have a div which works as a 'Edit' button with click event using jQuery. 我有一个div,它使用jQuery与点击事件一起充当“编辑”按钮。 I am changing text of that button 'Save' on click event. 我在点击事件中更改了“保存”按钮的文本。 Screen reader like JAWS reads "Edit button" when the focus comes to that button for the first time. 当JAWS的屏幕阅读器第一次将焦点移到该按钮时,它会读取“编辑按钮”。

But I want JAWS to recognise the change happened after click event ie After click JAWS should read "Save button". 但我希望JAWS能够识别单击事件后发生的更改,即单击JAWS之后应阅读“保存按钮”。 Any help? 有什么帮助吗? (Note that even after click, focus stays on the same button) (请注意,即使单击后,焦点仍停留在同一按钮上)

HTML code for that div/button: 该div /按钮的HTML代码:

<div role="button" class="js-btn" aria-label="Edit">Edit</div>

jQuery code to handle click event: jQuery代码来处理click事件:

$(document).on("click",".js-btn",function(e){
    $(this).innerHTML("Save");
    $(this).attr("aria-label","Save");
});

First: props for thinking of accessibility, and testing for it! 第一:思考可访问性的道具,并对其进行测试! But aria and its features are really meant to extend html for interactive things it can't natively handle. 但是aria及其功能实际上是为了扩展html来处理它本身无法处理的交互式内容。 And html can totally handle a button. html可以完全处理一个按钮。 So use button here, please, and you can skip the role and aria-label . 因此,请在此处使用button ,您可以跳过rolearia-label

Having the native semantics might be enough to make JAWS notice the change in text - not sure, but worth a try. 具有本地语义可能足以使JAWS注意到文本的更改-不确定,但值得尝试。 If it doesn't, you could add aria-live="polite" or aria-live="assertive" to your button and that should cue the SR to announce when its contents change. 如果没有,您可以在button添加aria-live="polite"aria-live="assertive" ,这应该提示SR在内容更改时宣布。 (Which one to use depends on how pushy you want to be about informing your user - polite won't interrupt whatever they're doing, assertive will.) (使用哪种方式取决于通知用户时您希望多大努力- polite不会打断他们正在做的任何事情, assertive会。)

<button aria-live="polite" class="js-btn">Edit</button>

(Note that even after click, focus stays on the same button) (请注意,即使单击后,焦点仍停留在同一按钮上)

If it's your expected behaviour, this is the answer to your question : as long as the focus stays on the element the screenreader won't re-read its data. 如果这是您的预期行为,那么这就是您的问题的答案:只要焦点停留在该元素上,屏幕阅读器就不会重新读取其数据。

Use two buttons, show the "Save" button after clicking on "Edit" and hide the "edit" button. 使用两个按钮,单击“编辑”后显示“保存”按钮,并隐藏“编辑”按钮。

<button id="edit">Edit</div>
<button id="save" class="hidden">Save</div>

$("#edit").on("click", function() {
    $(this).hide();
    $("#save").removeClass("hidden").focus();
});

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

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