阻止form表單默認提交的方法

前端代碼:

 <form method="post"  id="form" onsubmit="return false;" >
                    <div class="form-group">
                      <label for="username">用戶名:</label>
                      <input type="text" class="form-control" id="username" name="username" placeholder="請輸入用戶名" required>
                    </div>
                    <div class="form-group">
                      <label for="exampleInputEmail1">密 碼:</label>
                      <input class="form-control" type="password" name="password" id="example-password-input" placeholder="請輸入密碼" required>
                    </div>
                      <div class="form-group">
                      <label for="username">驗證碼:</label>
                      <input class="form-control" type="text" name="verify" placeholder="驗證碼" style="width: 50%;" required>
                          <div class="capcha"  >
                              <img src="{{:captcha_src()}}" alter="captcha" onclick="javascript:this.src='{{:captcha_src()}}?rand='+Math.random()" />
                          </div>
                      </div>
                    <button class="btn btn-general btn-blue" role="button" style="width: 100%;" id="submit">
                        <i fa fa-right-arrow></i>登錄
                    </button>
                  </form>

只要在form上添加代碼就可以:

onsubmit="return false;"

 

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