jquery submit()不能提交表單的解決方法
今天寫表單提交的時(shí)候需要增加一個(gè)確認(rèn)提示,所以沒有使用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">開始時(shí)間:</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">結(jié)束時(shí)間:</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('請(qǐng)確認(rèn)所填寫的信息是否正確?<br/>開始時(shí)間:' + start + '<br/>結(jié)束時(shí)間:' + end + '<br/>年利率:' + val, { icon: 3, title: '提示' }, function (index) { $("#form").submit(); layer.close(index); }); }); }) </script>
點(diǎn)擊提交按鈕出現(xiàn)確認(rèn)提示,但是確認(rèn)后就沒反應(yīng)了
但是將button的type改為submit卻又能提交
于是上jQuery API查找原因,看到以下這段文字頓時(shí)明白了:
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.
大概意思是表單和其子元素不宜用一個(gè)表單的屬性的屬性作為name或id的名稱,如submit, length, 和 method等,否則會(huì)產(chǎn)生沖突,名稱沖突可能就會(huì)導(dǎo)致這種情況。
原來是因?yàn)榘粹oid設(shè)為了submit
接下來只要將id改了就沒問題了
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- jQuery使用ajaxSubmit()提交表單示例
- Jquery ajaxsubmit上傳圖片實(shí)現(xiàn)代碼
- jquery的ajaxSubmit()異步上傳圖片并保存表單數(shù)據(jù)演示代碼
- jquery ajaxSubmit 異步提交的簡(jiǎn)單實(shí)現(xiàn)
- Jquery submit()無法提交問題
- 解決jquery submit()提交表單提示:f[s] is not a function
- jquery中使用$(#form).submit()重寫提交表單無效原因分析及解決
- 在jQuery ajax中按鈕button和submit的區(qū)別分析
- JQuery與JS里submit()的區(qū)別示例介紹
- jQuery ajaxSubmit 實(shí)現(xiàn)ajax提交表單局部刷新
相關(guān)文章
jQuery滿意度星級(jí)評(píng)價(jià)插件特效代碼分享
這篇文章主要介紹了jQuery滿意度星級(jí)評(píng)價(jià)插件特效,我們可以自定義每個(gè)五角星代表的分值,鼠標(biāo)滑過五角星時(shí)即可計(jì)算當(dāng)前的分值,這款jQuery評(píng)分插件非常簡(jiǎn)單而且實(shí)用。有需要的小伙伴可以參考下2015-08-08Jquery Easyui分割按鈕組件SplitButton使用詳解(17)
這篇文章主要為大家詳細(xì)介紹了Jquery Easyui分割按鈕組件SplitButton的使用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-12-12jQuery左右滾動(dòng)支持圖片放大縮略圖圖片輪播代碼分享
這篇文章主要介紹了jQuery左右滾動(dòng)支持圖片放大縮略圖圖片輪播效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2015-08-08jQuery EasyUI中的日期控件DateBox修改方法
下面小編就為大家?guī)硪黄猨Query EasyUI中的日期控件DateBox修改方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-11-11jQuery實(shí)現(xiàn)點(diǎn)擊文本框彈出熱門標(biāo)簽的提示效果
點(diǎn)擊文本框彈出熱門標(biāo)簽的效果實(shí)現(xiàn)方法有很多,在本文為大家詳細(xì)介紹下使用jQuery是如何實(shí)現(xiàn)的,感興趣的朋友不要錯(cuò)過2013-11-11jquery的ajax()函數(shù)傳值中文亂碼解決方法介紹
jquery的ajax()函數(shù)傳值中文亂碼解決方法介紹,需要的朋友可以參考下2012-11-11