jQuery: sending classname of fields of a form as an array
I have multiple forms, and I want to send classnames of these HTML form's fields in an array to a PHP server.
For example:
<form action="x.php">
<input type="text" name="name_ajax" class="classname1" /></p>
<input type="text" name="email_ajax" class="classname2" /></p>
<input type="submit" value="Submit" />
</form>
I want to send classname1
and classname2
in an array via jQuery and Ajax to server.php
af开发者_StackOverflow社区ter loading the page.
var classes = {};
$('form input').each(function(index, element){
classes[ $(element).attr('name') ] = $(element).attr('class');
});
$.post( 'path/to/php/script', $.param(classes) );
You might want to try
var classnames = [];
$("input").each(function(i, element) {
classnames.push(element.getClass());
}
// send code to server using jQuery post here
精彩评论