jquery插件EasyUI中form表單提交實例分享
之前用AJax給Controller傳遞參數(shù),然后再調(diào)用服務(wù)端的方法對數(shù)據(jù)庫進(jìn)行更改,今天碰到一個新的方法,就是表單的提交,這樣可以省去AJax傳參。
當(dāng)表單提交后,我們可以獲取表單上控件中的值,然后再調(diào)用服務(wù)端的方法對數(shù)據(jù)庫進(jìn)行更改。下面的一張截圖是具體的業(yè)務(wù)需求。
一、要實現(xiàn)的功能:從上面這個表單中,獲取控件中的值,然后傳遞給后臺。下面是表單代碼。
二、表單代碼
<div id="Editwin" class="easyui-window" title="編輯班級信息" style="width: 400px; height: auto;top:105px" data-options="closed:true,collapsible:false,minimizable:false,maximizable:false"> <div style="margin-top: 30px; margin-bottom: 30px; margin-left: 70px;"> <form id="EditForm" method="post"> <table> <tr> <td>班級名稱:</td> <td> <input class="easyui-validatebox" type="text" id="EditClassName" name="ClassName" data-options="required:true,validType:['maxLength[20]']"/> </td> </tr> <tr> <td> <input style="display:none" class="easyui-textbox" type="text" id="EditClassID" name="ClassID" data-options="required:true"/> </td> </tr> <tr> <td>所屬機構(gòu):</td> <td> <input id="EditOrganizationID" class="easyui-combobox" name="OrganizationName1" data-options="required:true"/> </tr> <tr> <td>年級:</td> <td> <input id="EditGradeID" class="easyui-combobox" name="GradeName" data-options="required:true"/> </tr> <tr> <td>備注:</td> <td> <textarea class="easyui-validatebox" id="NoteId" name="Note" validType:['maxLength[50]></textarea> </tr> </table> <div style="margin-top: 20px;"> <a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" style="margin-left: 10px;" onclick="EditsubmitForm()">確定</a> <a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" style="margin-left: 60px;" onclick="EditclearForm()">取消</a> </div> </form> </div> </div>
三、表單提交代碼
function EditsubmitForm() { $('#EditForm').form('submit', { url: "/BasicClass/ModifyClassInfo", onSubmit: function () { //表單提交前的回調(diào)函數(shù) var isValid = $(this).form('validate');//驗證表單中的一些控件的值是否填寫正確,比如某些文本框中的內(nèi)容必須是數(shù)字 if (!isValid) { } return isValid; // 如果驗證不通過,返回false終止表單提交 }, success: function (data) { //表單提交成功后的回調(diào)函數(shù),里面參數(shù)data是我們調(diào)用/BasicClass/ModifyClassInfo方法的返回值。 if (data > 0) { $.messager.show({ title: '提示消息', msg: '提交成功', showType: 'show', timeout: 1000, style: { right: '', bottom: '' } }); $('#dg').datagrid('reload'); // 重新載入當(dāng)前頁面數(shù)據(jù) $('#Editwin').window('close'); //關(guān)閉窗口 } else { $.messager.alert('提示信息', '提交失敗,請聯(lián)系管理員!', 'warning'); } } }); }
四、后臺Controller獲得表單中的數(shù)據(jù)
//獲得要添加的班級的名稱 string ClassName = Request.Form["ClassName"]; //獲得班級ID Guid ClassID = new Guid(Request.Params["ClassID"]); string ClassNote = Request.Form["Note"];
初學(xué)乍練,感覺比AJax傳參好用多了,因為AJax穿參時需要將各個參數(shù)的名字全部寫進(jìn)去,而表單提交時,默認(rèn)將表單中的內(nèi)容全部傳送過去,這樣表單中只要有什么數(shù)據(jù)我們就可以在后臺獲取什么數(shù)據(jù),當(dāng)然了,這些數(shù)據(jù)是提前綁定好的,或者是我們之前填寫好的。
以上就是本文的全部內(nèi)容,希望對大家學(xué)習(xí)jquery程序設(shè)計有所幫助。
相關(guān)文章
jQuery中的.bind()、.live()和.delegate()之間區(qū)別分析
jQuery中的.bind()、.live()和.delegate()之間區(qū)別分析,學(xué)習(xí)jquery的朋友可以參考下。2011-06-06jquery中focus()函數(shù)實現(xiàn)當(dāng)對象獲得焦點后自動把光標(biāo)移到內(nèi)容最后
當(dāng)對象獲得焦點后,自動把光標(biāo)移到內(nèi)容最后,使用focus()函數(shù)便可實現(xiàn),下面有個不錯的示例,感興趣的朋友可以參考下2013-09-09autoIMG 基于jquery的圖片自適應(yīng)插件代碼
為了防止圖片撐破布局,最常見的仍然是通過onload后獲取圖片尺寸再進(jìn)行調(diào)整,所以加載過程中仍然會撐破。2011-03-03模仿jQuery each函數(shù)的鏈?zhǔn)秸{(diào)用
模仿jQuery each函數(shù)的鏈?zhǔn)秸{(diào)用實現(xiàn)代碼。2009-07-07jquery插件開發(fā)之實現(xiàn)jquery手風(fēng)琴功能分享
需要一個手風(fēng)琴效果,就動手寫了一個。其實有多個現(xiàn)成的jQuery手風(fēng)琴插件可以用,但對比了一下,總感覺有些笨重,還是自己寫的脈絡(luò)自己最清楚,擴展起來也更容易些2014-03-03JQuery.closest(),parent(),parents()尋找父結(jié)點
在50個必備的實用jQuery代碼段看到關(guān)于closest()方法的介紹,考慮到開發(fā)過程中經(jīng)常有找爹的需求,以前用的都是parent()/parents()方法(還經(jīng)常找不到?。?,所以就此研究對比一下!2012-02-02