2016-06-23 31 views
2

I manage several websites that use a featured article scroller on their homepages, which allows the user to click a forward or back arrow in order to see the next article headline and blurb while remaining on the same page.是一个空元素(例如<a href="#">) valid for accessibility purposes?

I use WAVE's accessibility checker and any sites that have this particular plugin throw an error back because within the code there is an empty link, written as <a href="#">. Is there any way around this? I've defined a title attribute but the # is causing the empty link error to still come up.

Some places I've seen that this is perfectly acceptable and others claim this is a problem. What's the actual answer and potential workaround?

+2

[潜在相关答案](http://stackoverflow.com/a/19167175/2930477)。您不需要href属性,只需使用'返回'/' Next'。 [这个答案也是相关的](http://stackoverflow.com/a/10510353/2930477)。 – misterManSam

+0

任何暗示为什么我对我的回答有一个倒退? – aardrian

回答

5

Change the <a href="#"> to a <button> and put your event handler on it.

Some more context on which elements belongs where....

Does the Control Take Me to Another Page? Use an Anchor

If, when clicked, tapped, or activated by keyboard or voice (or insert novel interaction method here), the user is whisked to another URL (including an anchor on the same page), then use <a href="[URL]">. Make sure you use the href attribute and that it has a real URL, not a “#” (otherwise you’re probably relying on JavaScript, which is not at all necessary for a hyperlink). If an href points to just a “#”, then you’re probably doing it wrong. If it points to a named anchor as part of your progressive enhancement efforts, then that’s totally valid.

Does the Control Change Something on the Current Page? Use a Button

If, when activated, the user is not moved from the page (or to an anchor within the page), but instead is presented with a new view (message boxes, changes in layout, etc.), then use a <button>. While you could use an<input type="button">, it’s more likely you’ll get into conflicts with pre-existing styles and subsequent developers (like me).

Does the Control Submit Form Fields? Use a Submit

If, when activated, information the user has entered (either by manually typing or by choosing items on the screen) is being sent back to the server, then use an <input type="submit">. This has better live within a <form>. If you need more styling control or have to embed more than just a simple text string, use a <button type="submit"> instead.

Keyboard Considerations

Think of keyboard users for a moment. A hyperlink can be fired by pressing the enter key. But a true button can be fired by pressing the enter key or the space bar. When a hyperlink has focus and the user presses the space bar, the page will scroll one screenful. If there isn’t more to scroll then the user just experiences nothing. Given a set of interface elements that look the same, if some work with a space bar and some don’t, you can’t expect users to have much confidence in how the page behaves.

I think it’s also worth mentioning that events triggered by a space bar only fire when the key is released, whereas using the Enter key will fire the event as soon as you press the key down (prior to releasing it).

+0

感谢所有伟大的输入家伙,非常感谢。阿尔及利亚人,我不知道你为什么陷入低谷。非常有用的东西。我会尝试明天添加一个

+0

查看脚本是否专门查找'a',并且如果是这样的话,(或者替换为'button')。 – aardrian

+0

@aardrian低估了你的人没有阅读你的答案。不要问,并继续做好自己的工作。我非常感谢你的回答。 – Adam

0

Some source暗示<a href="#">link</a>将是一个无效的超文本引用,但实际上问题只会存在于超出WCAG 2范围的非JavaScript浏览器中。这不是您的问题,因为此处为this是不是那波认为一个错误。

这里的问题是,你有一个空的链接内容<a href="#"></a>,并且加入了title属性不满足波算法的事实。

如果你只关注为了满足WAVE,只需在链接中添加一些内容并使用任何CSS技巧来隐藏该公司ntent。

+0

感谢所有的建议家伙,我通过删除href属性来实现它。 :-) – NiamLeeson

+0

@NiamLeeson注意到删除'href'属性可能会导致屏幕阅读器不兼容,因此不会公布链接 – Adam

+0

因此,Adam,您认为最好的解决方案就是前面提到的