What's good practice for <button>?

Can it replace <a> tag or is it only meant for forms?

它可以替换标记还是只用于表单?

4 个解决方案

#1


4

A link links to something - at least it should! It is semantically wrong to do the following:

链接到某物-至少它应该!从语义上讲,这样做是错误的:

<a href="#" onclick="doSomething(); return false;">Do something</a>

This should be replaced with a button, as it is there for that purpose - it works as a trigger for something the user (programmer) specifies; the purpose of a <button type="button"> element is thus not clear. In contrast, the purpose of a link is very clear - it should point somewhere!

应该用一个按钮来替换它,因为它是为此目的而存在的——它作为用户(程序员)指定的东西的触发器;因此,不清楚

As HTML is a markup language, it does not matter all that much what you do, if you do not think SEO. You can achieve the same thing with a <a>tag as you can with a <button> tag, like a <span> can act exactly as a <div> - semantically though, it is incorrect.

由于HTML是一种标记语言,所以如果您不认为SEO,那么您做什么并不重要。您可以使用标记实现相同的功能,就像使用