【发布时间】:2020-05-13 11:40:15
【问题描述】:
我刚刚注意到这一点并且很好奇。我有两个带有 onClick 事件的<span>s,它们的作用基本相同;一个有type='button',但另一个没有。他们的行为完全一样。
除了更清楚它是什么之外,将
type='button'添加到元素还有什么意义?
即使是标准的button 元素,无论有无,其行为似乎都完全相同。
<button onclick="alert('Hello world!')">Click Me!</button>
&&
<button type="button" onclick="alert('Hello world!')">Click Me!</button>
【问题讨论】:
-
表单中没有 type=button 的按钮将提交整个表单。
-
在表格之外,有什么区别吗?