很少用button
一次别的童鞋在form中用到button,发现每次点击之后页面会刷新。
那么button的本义和应用场景到底是什么呢?
原因解释
只要button写了type=button
属性就可以了。
请始终为按钮规定 type 属性。Internet Explorer 的默认类型是 "button",而其他浏览器中(包括 W3C 规范)的默认值是 "submit"。
The type of the button. Possible values are:
- submit: The button submits the form data to the server. This is the default if the attribute is not specified, or if the attribute is dynamically changed to an empty or invalid value.
- reset: The button resets all the controls to their initial values.
- button: The button has no default behavior. It can have client-side scripts associated with the element's events, which are triggered when the events occur.
- menu: The button opens a popup menu defined via its designated <menu> element.
button详究
<button> elements are much easier to style than <input> elements. You can add inner HTML content (think
<em>
,<strong>
or even<img>
), and make use of :after and :before pseudo-element to achieve complex rendering while <input> only accepts a text value attribute.