Add a serializeObject jQuery funtion

This commit is contained in:
Thomas Gelf 2014-03-26 07:40:41 +00:00
parent ad0432f3be
commit 48913767d3
1 changed files with 20 additions and 1 deletions

View File

@ -42,11 +42,12 @@
}
})(console);
/* Get class list */
/* jQuery Plugins */
(function ($) {
'use strict';
/* Get class list */
$.fn.classes = function (callback) {
var classes = [];
@ -73,4 +74,22 @@
return classes;
};
/* Serialize form elements to an object */
$.fn.serializeObject = function()
{
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name] !== undefined) {
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;
};
})(jQuery);