将缺失的辅助功能属性插入 HTML 标记的 Java 程序
我需要编写一个 Java 程序,它将在 HTML 标记中插入缺少的辅助功能属性。
HTML 代码:
<html>
<body>
<input type="checkbox"/>Check it !!!
</body>
<html>
现在插入标题将使其可访问,但我不知道标题的值是什么。所以至少我们可以插入空白的title=""
。
对于这个特定的程序,我想做一些事情,比如 ava 代码将读取 HTML 文件并搜索输入标签并插入一个空白的 title=""
。
我该如何编写代码或者可以改进它?
I need to write a Java program which will insert the missing accessibility attributes in the HTML tag.
HTML CODE:
<html>
<body>
<input type="checkbox"/>Check it !!!
</body>
<html>
Now inserting a title will make it accessible, but I don't know what'll be the value of the title. So at least if we can insert the blank title=""
.
For this specific program I want to do some thing like the ava code will read the HTML file and will search for the input tag and will insert a blank title=""
.
How do I write the code or can I improve it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将
title=""
添加到元素不会提高可访问性。
您需要做的是手动编辑页面,添加实际上说明输入含义的
title
属性(或其他属性)。 (图像等也是如此)没有神奇的 Java 魔杖可以凭空生成有意义的描述。Adding
title=""
to<input>
elements is NOT going to improve accessibility.What you need to do is to manually edit the pages, adding
title
attributes (or whatever) that actually say what the inputs mean. (Ditto for images, etc, etc.) There is no magical Java wand that can generate meaningful descriptions out of thin air.就其价值而言,您的情况下正确的 HTML 是:
不要向元素添加 title="",这可能会使它们难以访问或引起混乱。标题是一个很难使用的元素;标题文本通常对键盘用户不可用(它通常仅在鼠标悬停时出现),并且屏幕阅读器可能会不一致地对待它;有些人会读取它而不是标签的内容,其他人会在标签的基础上读取它。据我所知,很少有案例表明标题是正确的解决方案。坚持使用标签(如上所述)、在图像上使用 alt 等等。
For what it's worth, the correct HTML in your case is:
Do not add title="" to elements, this will likely make them less accessible or cause confusion. Title is a tricky element to use; title text is generally not available to keyboard users (it usually only appears on mouse hover), and screenreaders may treat it inconsistently; some will read it instead of the tag's content, others will read it in addition to it. There are few cases I know of where title is the right solution; stick with using label (as above), using alt on images, and so on.