< a>与< button>与< div> vs<输入类型=“按钮">
问题描述:
我已经看过很多关于我想一个特定情况的我的一个特定情况"的帖子. HTML中的按钮.
I've seen so many posts along the lines of "I'd like to one-specific-thing for my one-specific-situation when it comes to buttons in HTML.
如果可以的话,我想在这里发表一篇专业的文章:
If I may, I'd like to get a professional take all in one post, here:
在HTML中制作按钮时,什么情况会导致以下情况:
When making buttons in HTML, what situations lead to:
-
<a>
是最好的答案? -
<button>
是最好的答案? -
<div>
是最好的答案? -
<input type='button'>
是最好的答案?
-
<a>
being the best answer? -
<button>
being the best answer? -
<div>
being the best answer? -
<input type='button'>
being the best answer?
答
有 好文章 很好地总结了差异
There's a good article that summarizes the differences nicely
简而言之:
| | 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 | | |