国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

jquery submit()不能提交表單的解決方法

2019-11-19 16:45:18
字體:
來源:轉載
供稿:網友

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

<form class="form-horizontal m-t" method="post" action="@Url.Action("Edit")" id="form">    <div class="row">      <div class="col-sm-12">        <div class="ibox float-e-margins">          <div class="ibox-title">            <h5>添加</h5>          </div>          <div class="ibox-content">            <div class="form-group">              <label class="col-sm-3 control-label">開始時間:</label>              <div class="col-sm-8">                <span>                  @(Model.annualRate_beginDate?.ToString("yyyy-MM-dd"))                </span>              </div>            </div>            <div class="form-group">              <label class="col-sm-3 control-label">結束時間:</label>              <div class="col-sm-8">                <input type="text" class="form-control" name="annualRate_endDate" id="annualRate_endDate" onclick="laydate({ istime: false, format: 'YYYY-MM-DD' })" value="@Model.annualRate_endDate.ToString("yyyy-MM-dd")" required>              </div>            </div>            <div class="form-group">              <label class="col-sm-3 control-label">年利息%:</label>              <div 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>              </div>            </div>            <div class="form-group">              <div 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>              </div>            </div>          </div>        </div>      </div>    </div>  </form>
<script type="text/javascript">  $(function () {    $("#submit").click(function () {      var start = '@(Model.annualRate_beginDate?.ToString("yyyy-MM-dd"))';      var end = $("#annualRate_endDate").val();      var val = $("#annualRate_rate").val();      layer.confirm('請確認所填寫的信息是否正確?<br/>開始時間:' + start + '<br/>結束時間:' + end + '<br/>年利率:' + val, { icon: 3, title: '提示' }, 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 complete list of rules and to check your markup for these problems, see DOMLint.

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

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

接下來只要將id改了就沒問題了

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 中方县| 青州市| 信宜市| 葵青区| 信阳市| 沾益县| 额济纳旗| 德格县| 庆安县| 博爱县| 民勤县| 嘉荫县| 涡阳县| 兴安县| 理塘县| 蒙阴县| 鹤峰县| 运城市| 柳江县| 宜兰市| 丰台区| 行唐县| 连平县| 弥勒县| 马边| 礼泉县| 页游| 和硕县| 金门县| 佛坪县| 临安市| 乳山市| 疏勒县| 沅陵县| 历史| 息烽县| 玉屏| 衡阳县| 木里| 长宁县| 旬邑县|