开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜