我看到很多帖子都是这样的:"我想在HTML中使用按钮时,针对我的具体情况而言,这是一个特定的事情.
如果可以的话,我想在一个帖子中找到专业人士,这里:
在HTML中创建按钮时,会导致以下情况:
<a> 是最好的答案? <button> 是最好的答案? <div> 是最好的答案? <input type='button'> 是最好的答案?Jaq*_*har 32
有一篇很好的文章很好地总结了这些差异
简而言之:
| | 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 | | |
Run Code Online (Sandbox Code Playgroud)
小智 15
通常,我尝试以最"语义的方式"和有用的方式使用HTML标记:
<a> tag:a用于"锚",当按钮是指向页面上的内容或外部内容的链接时,我使用它;divtag:这是一个简单的容器.我使用它时,我必须做简单的按钮,没有任何特定的工作,但真正的自定义风格(简单的动画,过渡,开放模式等).这是快乐的.<button> tag:根据W3,这是在页面上创建按钮的标准标记,因此在需要像onClick()这样的动作时使用它.<input type="button">tag:等于按钮标记,但是您需要它来表单提交,因为提交的浏览器<button>可以提交不同的值.我一般在表格上使用它.