这段代码有问题,但我没有足够的经验来解决这个问题。希望得到一些帮助。
jQuery(document).ready(function(){
$('#contactform').submit(function(){
var action = $(this).attr('action');
$("#message").slideUp(750,function() {
$('#message').hide();
$('#submit')
.attr('disabled','disabled');
if($('#process').val()=='1'){
$.post(action, $('#contactform').serialize(),
function(data){
document.getElementById('message').innerHTML = data;
$('#message').slideDown('slow');
$('#contactform img.loader').fadeOut('slow',function(){$(this).remove();
});
$('#submit').removeAttr('disabled');
if(data.match('success') != null) $('#contactform').slideUp('slow');
}
);
else {
$.post(action, $('#contactform').serialize(),
function(data){
document.getElementById('message').innerHTML = data;
$('#message').slideDown('slow');
$('#contactform img.loader').fadeOut('slow',function(){$(this).remove();
});
$('#submit').removeAttr('disabled');
if(data.match('success') !== null) $('#contactform').slideUp('slow');
}
);
});
return false;
});
});
});
谢谢!!!这是HTML:
<div id="message"></div>
<form method="post" action="contact.php" name="contactform" id="contactform">
<fieldset>
<input type="hidden" name="process" id="process" value="1">
<label for="name">Name<span class="required">*</span></label>
<input name="name" type="text" id="name" size="30" value="" />
<br />
<label for="email">Email<span class="required">*</span></label>
<input name="email" type="text" id="email" size="30" value="" />
<br />
<label for="phone">Phone<span class="required">*</span></label>
<input name="phone" type="tel" id="phone" size="30" value="" />
<br />
<label for="comments">Comments<span class="required">*</span></label>
<textarea name="comments" cols="40" rows="15" id="comments" style="width: 350px;"></textarea>
<br />
<label>Are you human?<span class="required">*</span></label>
<label class="accesskey" for="verify"> 3 + 1 =</label>
<input class="accesskey" name="verify" id="verify" size="4" value="" style="width: 30px;" /><br /><br />
<input type="submit" class="submit" id="submit" value="Submit" />
</fieldset>
</form>
</div><!--end contact-->
答案 0 :(得分:2)
您在}
之前错过了else {
,else
之前return false
的结尾应该是}
,而不是});
至少这是一回事。
还有令人不安的缺乏评论。
} else { // <= HERE add }
$.post(action, $('#contactform').serialize(),
function(data){
document.getElementById('message').innerHTML = data;
$('#message').slideDown('slow');
$('#contactform img.loader').fadeOut('slow',function(){$(this).remove();
});
$('#submit').removeAttr('disabled');
if(data.match('success') !== null) $('#contactform').slideUp('slow');
}
);
} // <= HERE remove );
return false;