jquery将form表单数据封装成js对象

// 将一个表单的数据返回成JS对象
$.fn.serializeObject = function() {
	var o = {};
	var a = this.serializeArray();
	$.each(a, function() {
		if (o[this.name]) {
			if (!o[this.name].push) {
				o[this.name] = [ o[this.name] ];
			}
			o[this.name].push(this.value || '');
		} else {
			o[this.name] = this.value || '';
		}
	});
	return o;
};

 

调用方式如下:

 

$(function() {
	$("#gridTable").jqGrid(
			{
				url : CTX+ "/transfer/querytransfer/doQueryByAjax.shtml",
				datatype : "json",
				mtype : 'POST',
				postData:$('#paramVo').serializeObject(),
				height : "auto",
				colNames : [ '提交时间', '完成时间', '交易号', '支出账户', '交易类型', '交易对方',
						'对方账号', '交易金额', '交易状态', '审核状态', '操作' ],
				colModel : [ {
					name : 'submitTime',
					width : 105,
					sorttype : "string"
				}, {
					name : 'finishTime',
					width : 105
				}, {
					name : 'txnId',
					width : 70
				}, {
					name : 'payAcct',
					width : 80,
					sorttype : "string"
				}, {
					name : 'txnCode',
					width : 50,
					formatter:function(v){
						var h="";
						if(v=="00700"){
							h="付款到银行";
						}else if(v=="00900"){
							h="付款到国付宝";
						}						
						return h;
					}
				}, {
					name : 'recName',
					width : 60
				}, {
					name : 'recAcct',
					width : 80,
					sorttype : "string"
				}, {
					name : 'txnAmt',
					width : 50
				}, {
					name : 'txnSts',
					width : 50
				}, {
					name : 'auditSts',
					width : 50
				}, {
					name : 'txnCode',
					width : 40,
					sorttype : "string",
					formatter:function(v,opts,rowObj){
						var h="啊";
						alert(dump(opts));
						alert(dump(rowObj));
						
						if(h=="00700"){
							h="批量详情";
						}
						
						return h;
					}
				} ],
				sortname : "submitTime",
				sortorder : "desc",
				viewrecords : true,
				gridview : true,
				rowNum : 10,
				rowList : [ 10, 20, 50,100],
				jsonReader : {
					repeatitems : false
				},
				pager : "#gridPager",
				caption : "付款记录列表"
			}).navGrid("#gridPager", {
		edit : false,
		add : false,
		del : false
	});

})

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值