首页 > 开发 > HTML > 正文

HTML 中定义 button行为时是否需要添加 type="button"? 好像没有这个也能正常使用.

2017-09-09 13:57:20  来源: 网友分享

比如:
<button type="button" onclick="document.getElementById('id1').style.color='red'">Click Here</button>

去掉 type="button" , 页面上的button也没啥变化啊

解决方案

<input type="button"/> type浏览器一般是默认为text 而非button
<button>OK</button> type可以是 button、reset、submit 不同浏览器可能默认不同,最好指定,不同于input的button的是 他内部可以放置内容,比如文本或图像。