1

I'm writing a one page store application and I've set up the menu as usual with ordinary anchor tags because it's been designed as such. Yet, while I will implement browser history, I will also preventDefault and treat them like buttons just opening a new view.

Should the menu be redesigned to show buttons instead anchor tags. It's familiarity vs. actual function (and semantic correctness, I believe).

4

1 回答 1

4

Let's consult the spec.

What is an <a> element?

If the a element has an href attribute, then it represents a hyperlink (a hypertext anchor) labeled by its contents.

If the a element has no href attribute, then the element represents a placeholder for where a link might otherwise have been placed, if it had been relevant, consisting of just the element's contents.

What about a <button> element?

The button element represents a button labeled by its contents.

So what does this mean?

If you're representing an actual link in your navigation (even if it's using the HTML5 History API), I say use an <a> element. If you're not, using a <button> might be better.

For navigation, I'd probably use an a tag.

Semantic HTML is not the only issue here

Another issue is SEO, crawlers like GoogleBot will have a much easier time figuring out they should follow a links than buttons.

于 2013-06-09T20:25:23.963 回答