【发布时间】:2014-07-21 01:38:36
【问题描述】:
我的网站有这个功能:
$(document).on('submit','form.contactform',function(){
$(".contactTable tr:last-child td:first-child").animate({
'padding-left' : 5
}, 2000, function(){
var url = "contactSubmit.php"; // the script where you handle the form input.
$.ajax({
type: "POST",
url: url,
data: $("#contactform").serialize(), // serializes the form's elements.
success: function()
{
//window.location = 'index.php?send='.'succ'; // show response from the php script.
},
fail: function()
{
alert("An error has ocurred! :O");
}
});
});
return false;
});
我想要做的是,当用户点击提交按钮时,我会为左边的一辆小汽车制作动画,然后提交表单。 (是的,这是家庭作业)。 但是正在发生的事情是在动画完成之前发送表单.. 有什么问题?
编辑: 改为:
$("#contactform").submit( function() {
var url = "contactSubmit.php"; // the script where you handle the form input.
$.ajax({
type: "POST",
url: url,
beforeSend: $(".contactTable tr:last-child td:first-child").animate({'padding-left' : 5}, 2000),
data: $("#contactform").serialize(), // serializes the form's elements.
success: function()
{
window.location = 'index.php?send='.'succ'; // show response from the php script.
},
error: function()
{
alert("An error has ocurred! :O");
}
});
return false;
});
但是现在什么都没有发生,只是发送了表单
编辑 2: 这是表格的 html:
<form id= "contactform" class="contactform" method="post" action="contactSubmit.php">
<table class="contactTable">
<tr><td>Name</td> <td><input class="inputField" placeholder="John Doe" type="text" name="name" required></td></tr>
<tr><td>Email</td><td><input class="inputField" type="text" placeholder="example@example.com"
title="Please enter a valid email." name="email" pattern="[a-zA-Z]+@[a-zA-Z]+.[a-zA-Z]+(.[a-zA-Z]+)?">
</td></tr>
<tr><td>Topic</td> <td> <select class="inputField" name="topic">
<option value="great">Compliment!</option>
<option value="good">Neutral</option>
<option value="bad">Bad!</option>
<option value="other">What?</option>
</select></td></tr>
<tr><td>Car</td> <td> <select class="inputField" name="car">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select></td></tr>
<tr><td>Message</td><td><textarea class="inputField" name="msg"
placeholder="Your message here." required></textarea></td></tr>
<tr><td><img src="resources/littleCar.png" alt="Little Car" class="littlecar"></td>
<td><input type="submit" class="submitButton" value="Submit"></td>
</tr>
</table>
</form>
我还有另一个用于字段检查的 jquery 函数:
$(document).ready(function () {
$('form').h5Validate();
});
【问题讨论】:
标签: javascript jquery forms web