jqurey 获取 form 表单中所有数据,支持多维数组
来源:互联网 发布:深圳国税开票软件 编辑:程序博客网 时间:2024/06/07 03:39
jqurey 获取 form 表单中所有数据,支持多维数组
JQurey.formHelper
- jQuery.formHelper = {
- status : true,
- rules : null,
- tagName : '',
- error : function (msg)
- {
- console.log(msg);
- jQuery.formHelper.status = false;
- return false;
- },
- success : function ()
- {
- jQuery.formHelper.status = true;
- return true;
- },
- regRul : {
- "require" : /.+/,
- "email" : /^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$/,
- "url" : /^http:\\/\\/[A-Za-z0-9]+\\.[A-Za-z0-9]+[\\/=\\?%\\-&_~`@[\\]\\":+!]*([^<>\\"\\"])*$/,
- "currency": /^\\d+(\\.\\d+)?$/,
- "number" : /^\\d+$/,
- "zip" : /^[1-9]\\d{5}$/,
- "integer" : /^[-\\+]?\\d+$/,
- "double" : /^[-\\+]?\\d+(\\.\\d+)?$/,
- "english" : /^[A-Za-z]+$/
- },
- otherRul : {
- ">" : function (val, point, msg)
- {
- return (val > point) ? jQuery.formHelper.success() : jQuery.formHelper.error(msg);
- },
- 'in' : function (val, point, msg)
- {
- return ($.inArray(val, point) != -1) ? jQuery.formHelper.success() : jQuery.formHelper.error(msg);
- },
- '==' : function (val, point, msg)
- {
- return (val == point) ? jQuery.formHelper.success() : jQuery.formHelper.error(msg);
- },
- 'remote': function (val, point, msg)
- {
- $.ajax({
- type : "post",
- dataType: "json",
- url : point[0],
- data : jQuery.formHelper.tagName + '=' + val,
- success : point[1]
- });
- }
- },
- getClass : function (object)
- {
- return Object.prototype.toString.call(object).match(/^\\[object\\s(.*)\\]$/)[1];
- },
- getFormData: function (id)
- {
- var _url = $('#' + id).serialize();
- var fixStr = function (str)
- {
- return decodeURIComponent(str.replace(/\\+/g, '%20'));
- };
- var act1 = function (str)
- {
- str.replace(reg1, function (a, b, c)
- {
- arg[b] = (typeof c == 'undefined' ? '' : c);
- });
- };
- var act2 = function (str)
- {
- str.replace(reg2, function (a, b, c, d)
- {
- arg[b] = arg[b] || {};
- arg[b][c] = (typeof d == 'undefined' ? '' : d);
- });
- };
- var act3 = function (str)
- {
- str.replace(reg3, function (a, b, c, d, e)
- {
- arg[b] = arg[b] || {};
- arg[b][c] = arg[b][c] || {};
- arg[b][c][d] = (typeof e == 'undefined' ? '' : e);
- });
- };
- var url = fixStr(_url).replace(/'|"/g, '');
- var arr = url.split('&');
- var length = arr.length;
- var reg1 = /(\\w+)=(\\w+)?/ig;
- var reg2 = /(\\w+)\\[(\\w+)\\]=(\\w+)?/ig;
- var reg3 = /(\\w+)\\[(\\w+)\\]\\[(\\w+)\\]=(\\w+)?/ig;
- var arg = {};
- for (var i = 0; i < length; i++)
- {
- var act = reg1.test(arr[i]) ? act1 : (reg2.test(arr[i]) ? act2 : (reg3.test(arr[i]) ? act3 : ''));
- act(arr[i]);
- }
- return arg;
- },
- submit : function (formId, submitBtnId, action, success)
- {
- $('#' + submitBtnId).click(function ()
- {
- jQuery.formHelper.check(jQuery.formHelper.rules);
- if (jQuery.formHelper.status)
- {
- $.ajax({
- async : false,
- type : "post",
- dataType: "json",
- url : action,
- data : $('#' + formId).serialize(),
- success : success
- });
- }
- });
- },
- check : function (rules)
- {
- jQuery.formHelper.rules = rules;
- $(rules).each(function ()
- {
- jQuery.formHelper.tagName =this[0];
- var val = $('[name=' + this[0] + ']').val();
- var rul = this;
- jQuery.formHelper.done(rul, val);
- });
- },
- validate : function (rules)
- {
- jQuery.formHelper.rules = rules;
- $(rules).each(function ()
- {
- jQuery.formHelper.tagName =this[0];
- $('[name=' + this[0] + ']').keyup({rul: this}, function (event)
- {
- var val = $(this).val();
- var rul = event.data.rul;
- jQuery.formHelper.done(rul, val);
- });
- });
- return this;
- },
- done : function (rul, val)
- {
- if ($.inArray(rul[1], jQuery.formHelper.regRul) != -1)
- {
- return (jQuery.formHelper.regRul[(rul[1])].test(val)) ? jQuery.formHelper.success() : jQuery.formHelper.error(rul[2]);
- }
- else if (jQuery.formHelper.otherRul.hasOwnProperty(rul[1]))
- {
- return jQuery.formHelper.otherRul[rul[1]](val, rul[3], rul[2]);
- }
- else if (jQuery.formHelper.getClass(rul[1]) == 'RegExp')
- {
- return ((rul[1]).test(val)) ? jQuery.formHelper.success() : jQuery.formHelper.error(rul[2]);
- }
- else
- {
- return jQuery.formHelper.error('没有匹配规则');
- }
- }
- };
1 0
- jqurey 获取 form 表单中所有数据,支持多维数组
- js获取form表单所有数据
- js获取form表单所有数据
- js获取form表单所有数据
- js获取form表单所有数据
- JS获取form表单的所有数据
- js获取form表单所有数据的简单方法
- js获取form表单所有数据的简单方法
- React-Form表单数据获取
- ExtJs4 中 获取grid列表数据绑定到form表单
- ExtJs4 中 获取grid列表数据绑定到form表单
- 获取form表单所有输入内容
- 用ajax提交form表单所有数据
- 禁用form表单中所有控件
- 使用js获取表单form的数据
- Ajax获取form表单提交数据
- 原生js实现获取form表单数据
- el表达式和获取form表单数据
- 整数划分
- Core Animation - 视觉效果<三>
- Codefoences Round #302 A (div1)
- vc连接access数据库及数据表基本操作
- 【胖鱼头】基于Sentinel的Redis主从分片集群搭建
- jqurey 获取 form 表单中所有数据,支持多维数组
- 惊呼——SVM支持向量机三重境界!
- 20160311 调研
- POJ 1061 青蛙的约会
- 链式栈C++实现
- 《Storm入门》中文版
- 玩转Nodejs日志管理log4js
- 解决php ZipArchive执行后无法生成zip文件的问题
- 获取指定的斜杠后面的内容