<form action="#" method="post"> <input type="text" name="username" class="username" placeholder="請輸入您的用戶名!"> <input type="password" name="password" class="password" placeholder="請輸入您的用戶密碼!"> <input type="Captcha" class="Captcha" name="Captcha" placeholder="請輸入驗證碼!"> <button type="submit" class="submit_button">登陸</button> <div class="error"><span>+</span></div> </form>
每次咱們點擊button,button都會自動跳轉刷新。如何阻止它呢?很簡單!post
將button代碼改爲spa
<button type="submit" class="submit_button" onClick=「submitAction();return false;」>登陸</button>
這樣它就不會執行默認表單提交了!code
若是不喜歡這樣處理,也能夠在js按鈕觸動代碼末尾中添加return false;一樣能夠達到相同效果!orm