我正在尝试定位几种形式:#form1,#form2,#form3,并且无法使其正常工作。
$(document).ready(function() {
var target = $('#form').val();
target = (target.indexOf('#') === 0? target : '#' + target);
$(target).validate({
rules: {
name : { required: true },
},
submitHandler: function(form) {
var options = {
target : target,
};
$(form).ajaxSubmit(options);
}
});
});
HTML .....
<form id="form1" action="order.php" method="post">.....</form>
<form id="form2" action="order.php" method="post">.....</form>
答案 0 :(得分:1)
$('#form,#form1,#form2').each(function () {
$(this).validate({
rules: {
name: {
required: true
}
},
submitHandler: function (form) {
alert($(form).attr('id') + ' successful');
}
});
});
答案 1 :(得分:0)
你无法给这些表格一个类并定位该类?当你想要通常以正确的方式定位页面中的几个元素时。
HTML
<form id="form1" action="order.php" method="post" class="target-form">.....</form>
<form id="form2" action="order.php" method="post" class="target-form">.....</form>
JS
$('.target-form')