button按鈕在IE瀏覽器默認(rèn)類型是“button”咪惠,在其他瀏覽器默認(rèn)為submit類型,所以在form表單內(nèi)用到的button按鈕必須要定義其type屬性覆醇,如果指明type="submit"或者不寫該屬性,點(diǎn)擊按鈕時(shí)會(huì)觸發(fā)整個(gè)頁面的刷新永脓。
<button></button>相當(dāng)于<button type="submit"></button>
解決辦法:
1)在<button>標(biāo)簽中添加屬性type="button;
? ? ? <button type="button"></button>
2)將<button>改為<input>標(biāo)簽
? ? ? <input type="button" />
3)在button的點(diǎn)擊事件中加入阻止默認(rèn)事件執(zhí)行的代碼段(JavaScript/jQuery)徽缚。
? ? ? ?$('button').on('click',function(e) {
? ? ????????????e.preventDefault();
????????});
4)可以在監(jiān)聽按鈕提交(點(diǎn)擊)的方法中添加return false阻止刷新革屠。
? ? ? 在ajax外部添加return false; 可以阻止刷新