爲什麼點擊button會自動刷新頁面

因爲button標籤按鈕會提交表單。

解決方法如下:

1、將<button></button>改爲<input type="button">  或者直接在<button>中添加屬性 type="button".

2、在button的點擊事件中加入“e.preventDefult()” 

$('btn').click(function(e){

e.preventDefult();

});

點擊button刷新的幾種常用代碼:

1、<input type=button value=刷新 οnclick="history.go(0)">

2、<input type=button value=刷新 οnclick="location.reload()">

3、<input type=button value=刷新 οnclick="location=location">

4、<input type=button value=刷新 οnclick="location.assign(location)">

5、<input type=button value=刷新 οnclick="document.execcommand(refresh)">

6、<input type=button value=刷新 οnclick="window.navigate(location)">

7、<input type=button value=刷新 οnclick="location.replace(location)">

8、<input type=button value=刷新 οnclick="window.open(自身的文件,_self)">

9、<input type=button value=刷新 οnclick=document.all.webbrowser.execwb(22,1)>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章