2

我正在尝试动态插入标签中的值,这些值我将对有视力的用户隐藏,但将由屏幕阅读器为显示在列中的视障用户读取。如何使用 dojo 完成此任务?

<html>
<head>
<title>Dojo Labels</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/dojo/1.3.2/dojo/dojo.xd.js"></script>
<style type="text/css">
    .style1
    {
        width: 154px;
    }
</style>
</head>
<body>
<table style="width: 51%; height: 204px;">
    <tr>
        <td class="style1">
            &nbsp;
            <input id="Checkbox1" type="checkbox" />
            <label for="Checkbox1"></label>
        </td>
        <td>
           John
        </td>
        <td>
            Doe
        </td>
    </tr>
    <tr>
        <td class="style1">
            &nbsp;
            <input id="Checkbox2" type="checkbox" />
            <label for="Checkbox2"></label>
        </td>
        <td>
            Jane
        </td>
        <td>
            Doe
        </td>
    </tr>
    <tr>
        <td class="style1">
            &nbsp;
            <input id="Checkbox3" type="checkbox" />
            <label for="Checkbox3"></label>
        </td>
        <td>
           John
        </td>
        <td>
           Smith
        </td>
    </tr>
</table>
</body>
</html>
4

3 回答 3

6

如果您只需要动态更改标签,那么您可以试试这个:

dojo.query("label[for=Checkbox1]")[0].innerHTML = "text";

但是,如果您需要逻辑来检测它是屏幕阅读器还是浏览器,那么我无能为力。但是您可能总是可以使用文本呈现标签,只需添加样式 display:none;

<label for="Checkbox2" style="display:none;">text</label>
于 2010-11-24T17:48:11.843 回答
0

也许这个会有所帮助。

获取标签内容:dijit.byId("btnButtonName").get("label")=="SomeName");

设置标签内容:dijit.byId("btnButtonName").set("label", "SomeName");

于 2013-05-30T06:20:41.773 回答
0

不完全确定我是否完全理解您在做什么,但是 dojo 提供了一种允许您修改 DOM 节点的属性值的方法。它被称为dojo.attr()

于 2010-11-24T17:38:13.150 回答