参考示例:表单:加载、保存
只需要一个id即可创建表单对象:
var form = new mini.Form("#form1");
$.ajax({ url: "../data/FormService.aspx?method=LoadData", type: "post", success: function (text) { var data = mini.decode(text); //反序列化成对象 form.setData(data); //设置多个控件数据 } });
//提交表单数据 var form = new mini.Form("#form1"); var data = form.getData(); //获取表单多个控件的数据 var json = mini.encode(data); //序列化成JSON $.ajax({ url: "../data/FormService.aspx?method=SaveData", type: "post", data: { submitData: json }, success: function (text) { alert("提交成功,返回结果:" + text); } });
form.clear();
form.reset();