jquery.myext.js 287 B

123456789101112131415
  1. $.fn.form2json = function() {
  2. var o = {};
  3. var a = this.serializeArray();
  4. $.each(a, function() {
  5. if (o[this.name]) {
  6. if (!o[this.name].push) {
  7. o[this.name] = [ o[this.name] ];
  8. }
  9. o[this.name].push(this.value || '');
  10. } else {
  11. o[this.name] = this.value || '';
  12. }
  13. });
  14. return o;
  15. }