首頁 > web前端 > js教程 > 主體

jquery submit()不能提交表單如何解決

小云云
發布: 2018-01-17 13:19:25
原創
1966 人瀏覽過

本文主要為大家詳細介紹了jquery submit()不能提交表單的解決方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能幫助到大家。

 今天寫表單提交的時候需要增加一個確認提示,所以沒有使用submit按鈕提交,改用jq的submit(),然後問題了


<form class="form-horizontal m-t" method="post" action="@Url.Action("Edit")" id="form">
    <p class="row">
      <p class="col-sm-12">
        <p class="ibox float-e-margins">
          <p class="ibox-title">
            <h5>添加</h5>
          </p>
          <p class="ibox-content">
            <p class="form-group">
              <label class="col-sm-3 control-label">开始时间:</label>
              <p class="col-sm-8">
                <span>
                  @(Model.annualRate_beginDate?.ToString("yyyy-MM-dd"))
                </span>
              </p>
            </p>
            <p class="form-group">
              <label class="col-sm-3 control-label">结束时间:</label>
              <p class="col-sm-8">
                <input type="text" class="form-control" name="annualRate_endDate" id="annualRate_endDate" onclick="laydate({ istime: false, format: &#39;YYYY-MM-DD&#39; })" value="@Model.annualRate_endDate.ToString("yyyy-MM-dd")" required>
              </p>
            </p>
            <p class="form-group">
              <label class="col-sm-3 control-label">年利息%:</label>
              <p class="col-sm-8">
                <input type="number" step="0.01" class="form-control" id="annualRate_rate" name="annualRate_rate" value="@Model.annualRate_rate.ToString("#0.00")" required>
              </p>
            </p>
            <p class="form-group">
              <p class="col-sm-4 col-sm-offset-2">
                <button class="btn btn-lg btn-primary" id="submit_btn" type="button">
                  提交
                </button>

                <a class="btn btn-lg btn-white" href="@Url.Action(" rel="external nofollow" Index")">
                  取消
                </a>
              </p>
            </p>
          </p>
        </p>

      </p>
    </p>
  </form>
登入後複製


<script type="text/javascript">
  $(function () {
    $("#submit").click(function () {
      var start = &#39;@(Model.annualRate_beginDate?.ToString("yyyy-MM-dd"))&#39;;
      var end = $("#annualRate_endDate").val();
      var val = $("#annualRate_rate").val();
      layer.confirm(&#39;请确认所填写的信息是否正确?<br/>开始时间:&#39; + start + &#39;<br/>结束时间:&#39; + end + &#39;<br/>年利率:&#39; + val, { icon: 3, title: &#39;提示&#39; }, function (index) {
        $("#form").submit();
        layer.close(index);
      });
    });
  })
</script>
登入後複製

點擊提交按鈕出現確認提示,但是確認後就沒反應了

但是將button的type改為submit卻又能提交

於是上jQuery API查找原因,看到以下這段文字頓時明白了:

Additional Notes:

Forms and their child elements should not use input names or ids that conflict with properties of a form, such as submit, length, or method. Name conflicts can cause confusing failures. For a pleurete Name conflicts can cause confusing failures. For a pleures. For list of list list of list for these problems, see DOMLint.

大概意思是表單和其子元素不宜用一個表單的屬性的屬性作為name或id的名稱,如submit, length, 和method等,否則會產生衝突,名稱衝突可能會導致這種情況。

原來是因為按鈕id設為了submit

相關推薦:

jQuery如何使用ajaxSubmit()提交表單實例詳解

JQuery與JS裡submit()的區別範例介紹

表單元素的submit()方法和onsubmit事件應用概述_基礎知識

以上是jquery submit()不能提交表單如何解決的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!