aria-describedby 但默认为空文本错误 - 这是正确的吗?
aria-describedby but the empty text error by default - is this correct?
当我们需要显示错误时(当错误发生时,一些元素被添加到 DOM),有一个值得信赖的 example for aria-describedby
,它变成:
<p><label for="email">Email address: [*]</label>
<input type="text" name="email" id="email" aria-describedby="err_1" class="error"> <span class="errtext" id="err_1">Error: Input data missing</span></p>
而不是
<p><label for="email">Email address: [*]</label>
<input type="text" name="email" id="email"> </p>
如果默认情况下只是错误文本为空,从可访问性的角度来看 好吗?因此,当发生错误时,只会添加其文本。
默认情况下(无错误文本)- 此代码看起来正确吗?
<p><label for="email">Email address: [*]</label>
<input type="text" name="email" id="email" aria-describedby="err_1" class="error"> <span class="errtext" id="err_1"></span></p>
这样我们就可以将 span
中的唯一文本从空白更改为一些文本。
My question is: is it fine from the accessibility point of view, if by default just the error text is empty? As result, when error happens, then just its text gets added.
是的。这在那里讨论:Describing aria-describedby(读取空元素时可能会导致短暂的停顿)
如果aria-describedby
指向的元素是空的,那么什么都没有被读取,所以你没问题。当您向 <span>
添加文本时,当用户将焦点 返回 到输入时,将读取文本。添加文本后,不会 阅读。为此,您需要 aria-live
(这是个好主意)。
<p>
<label for="email">Email address: [*]</label>
<input type="text" name="email" id="email" aria-describedby="err_1" class="error">
<span class="errtext" id="err_1" aria-live="polite"></span>
</p>
当我们需要显示错误时(当错误发生时,一些元素被添加到 DOM),有一个值得信赖的 example for aria-describedby
,它变成:
<p><label for="email">Email address: [*]</label>
<input type="text" name="email" id="email" aria-describedby="err_1" class="error"> <span class="errtext" id="err_1">Error: Input data missing</span></p>
而不是
<p><label for="email">Email address: [*]</label>
<input type="text" name="email" id="email"> </p>
如果默认情况下只是错误文本为空,从可访问性的角度来看 好吗?因此,当发生错误时,只会添加其文本。
默认情况下(无错误文本)- 此代码看起来正确吗?
<p><label for="email">Email address: [*]</label>
<input type="text" name="email" id="email" aria-describedby="err_1" class="error"> <span class="errtext" id="err_1"></span></p>
这样我们就可以将 span
中的唯一文本从空白更改为一些文本。
My question is: is it fine from the accessibility point of view, if by default just the error text is empty? As result, when error happens, then just its text gets added.
是的。这在那里讨论:Describing aria-describedby(读取空元素时可能会导致短暂的停顿)
如果aria-describedby
指向的元素是空的,那么什么都没有被读取,所以你没问题。当您向 <span>
添加文本时,当用户将焦点 返回 到输入时,将读取文本。添加文本后,不会 阅读。为此,您需要 aria-live
(这是个好主意)。
<p>
<label for="email">Email address: [*]</label>
<input type="text" name="email" id="email" aria-describedby="err_1" class="error">
<span class="errtext" id="err_1" aria-live="polite"></span>
</p>