【问题标题】:How to use aria-label and aria-labelledby to get visible and non-visible(customized) value from the reader?如何使用 aria-label 和 aria-labelledby 从阅读器获取可见和不可见(自定义)值?
【发布时间】:2018-03-16 07:14:14
【问题描述】:

有没有办法通过使用 aria-label 或使用 aria-labelledby 或任何其他属性来获取可见标签名称和自定义名称

例如下面的代码是:-

<div>
    <div id="shankar">Name</div>
    <input type="text" aria-labelledby="shankar"/>
</div>
<div>
    <div id="set-address">Address</div>
    <input type="text" aria-label="set-address"/>
</div>

读者:- 1.名称编辑文字(第一个输入框) 2.设置地址编辑文本(第二个输入框)

我已经通过链接enter link description here

我应该怎么做才能得到这样的消息:- Set-address for Address 编辑文本? 我应该在这里使用哪个属性?

【问题讨论】:

    标签: javascript html css screen-readers web-accessibility


    【解决方案1】:

    对于屏幕阅读器,并且因为您的情况是用于表单输入,所以正确的语法是:

    <div>
        <label for="shankar">Name</label>
        <input type="text" id="shankar"/>
    </div>
    

    您必须通过针对“id”属性的属性关联标签标签。

    如果您在其他情况下(如下拉菜单或选项卡面板):

    将类似于(此处示例显示翻译的案例下拉列表):

        // My label structure
    <button id="associatedLang" role="button" title="" aria-expanded="true">
        <span class="ps-current-lang">FR</span>
        <span aria-hidden="true" class="ps-icon ps-icon-chevron-down"></span>
        <span class="sr-only">Changer de langue</span>
    </button>
    
    //MY associated content 
    
    <ul aria-labelledby="associatedLang">
        <li class="ng-star-inserted">
            <a target="_self" href="####" lang="en" title="EN - English">
            EN
          </a>
        </li>
    </ul>
    

    【讨论】:

    • 嗨,Yanis,我想让值可见和不可见。您能否建议我应该使用哪个属性来获得两者。谢谢
    • 我不确定是否理解您的问题,如果只是为了通知屏幕阅读器,您的“附加内容”不会显示,您必须处理必须为 true 的 aria-expanded 或根据您当前的状态为假。然后在附加的内容(必须切换)上,根据您当前的状态添加 aria-hidden true 或 false
    猜你喜欢
    • 1970-01-01
    • 2013-11-06
    • 2017-10-07
    • 1970-01-01
    • 1970-01-01
    • 2014-05-13
    • 2020-10-31
    • 1970-01-01
    • 2012-05-08
    相关资源
    最近更新 更多