If I may, I'd like to get a professional take all in one post, here:
When making buttons in HTML, what situations lead to:
<a>
being the best answer? <button>
being the best answer? <div>
being the best answer? <input type='button'>
being the best answer?答案 0 :(得分:24)
有good article可以很好地总结差异
简而言之:
| | General usage | Complex designs | Can be disabled |
|-----------------------|----------------------------|-----------------|-----------------|
| <button> | General button purpose. | Yes | Yes |
| | Used in most cases | | |
| --------------------- | -------------------------- | --------------- | --------------- |
| <input type="button"> | Usually used inside | No | Yes |
| | forms | | |
| --------------------- | -------------------------- | --------------- | --------------- |
| <a> | Used to navigate to | Yes | No |
| | pages and resources | | |
| --------------------- | -------------------------- | --------------- | --------------- |
| <div> | Can be used for clickable | Yes | No |
| | area which is not button | | |
| | or link by definition | | |
答案 1 :(得分:14)
通常,我尝试以最常用的语义方式使用HTML标记。有用的方式:
<a>
标记:a用于&#34;锚定#34;,当按钮是指向页面上内容或外部内容的链接时,我会使用它; div
tag:这是一个简单的容器。我使用它时,我必须做简单的按钮,没有任何特定的工作,但真正的自定义风格(简单的动画,过渡,开放模式等)。这是快活的。<button>
标签:根据W3,这是在页面上创建按钮的标准标签,因此在需要像onClick()这样的动作时使用它。<input type="button">
标记:等于按钮标记,但您需要它来表单提交,因为使用<button>
提交的浏览器可以提交不同的值。我一般在表格上使用它。