在button中添加 type="button"和不添加的区别

<button  type="button"  class="btn btn-success" onclick="page.search()">搜索</button>

我在项目中通过按钮搜索的时候  其中一个页面没有给button添加type="button" 时  点击搜索会重新进入页面

后台百度才知道  Internet Explorer 的默认类型是 "button",而其他浏览器中(包括 W3C 规范)的默认值是 "submit"。 所以请始终为按钮规定 type 属性。

重要事项:如果在 HTML 表单中使用 button 元素,不同的浏览器会提交不同的值。Internet Explorer 将提交 <button> 与 <button/> 之间的文本,而其他浏览器将提交 value 属性的内容。请在 HTML 表单中使用 input 元素来创建按钮。

详细讲解了 http://www.cnblogs.com/purediy/archive/2012/06/10/2544184.html

猜你喜欢

转载自www.cnblogs.com/wdd-cindy/p/9007467.html
今日推荐