我有多个表单,我想将这些HTML表单字段的类名发送到PHP服务器。
例如:
<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>
答案 0 :(得分:4)
var classes = {};
$('form input').each(function(index, element){
classes[ $(element).attr('name') ] = $(element).attr('class');
});
$.post( 'path/to/php/script', $.param(classes) );
答案 1 :(得分:1)
您可能想尝试
var classnames = [];
$("input").each(function(i, element) {
classnames.push(element.getClass());
}
// send code to server using jQuery post here