form表单下<button>点击后会刷新页面,<input type="button">不会。
这样有时候你在用<button>按钮就需要注意了。
例如:
fun()
{
document.getElementById("content").innerHTML = "xxxx"
}
<body>
<form id="form1" runat="server">
<div>
<table>
<tr id="lct">
</tr>
<tr id="ms">
</tr>
</table>
</div>
<div id="content" style="display:none" >
asdfasf
</div>
<button οnclick="fun()">btn</button>
<input type="button" οnclick="fun()" value="按钮" />
</form>
</body>
<button>btn点击后会出现页面一瞬间显示为:xxxx,但马上又变回了
asdfasf
原因:这是因为在大部分浏览器下面form表单下button点击后会提交数据刷新页面
解决办法:使用
<input type="button">
或者给button加上一个type="button"属性