Created
August 29, 2019 11:08
-
-
Save mkmms/aa9621408672ef1715d03615a3450c33 to your computer and use it in GitHub Desktop.
jQuery get params from any parent element
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.fn.generateParams = function() { | |
var rsubmittable = /^(?:input|select|textarea|keygen)/i; | |
var rcheckableType = ( /^(?:checkbox|radio)$/i ); | |
var rCRLF = /\r?\n/g; | |
return this | |
.find("input, select, textarea, keygen") | |
.not(":disabled") | |
.filter(function(){ | |
var type = this.type; | |
return this.name && !jQuery( this ).is( ":disabled" ) && | |
rsubmittable.test( this.nodeName ) && | |
( this.checked || !rcheckableType.test( type ) ); | |
}) | |
.map( function( i, elem ) { | |
var val = jQuery( this ).val(); | |
return val == null ? | |
null : | |
jQuery.isArray( val ) ? | |
jQuery.map( val, function( val ) { | |
return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) }; | |
} ) : | |
{ name: elem.name, value: val.replace( rCRLF, "\r\n" ) }; | |
} ).get(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment