Jquery 这段代码有什么问题吗?
这段代码有点问题,但我没有足够的经验来理解它。希望得到一些帮助Jquery 这段代码有什么问题吗?,jquery,Jquery,这段代码有点问题,但我没有足够的经验来理解它。希望得到一些帮助 jQuery(document).ready(function(){ $('#contactform').submit(function(){ var action = $(this).attr('action'); $("#message").slideUp(750,function() { $('#message').hide(); $('#su
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-->
您在else{之前缺少一个},而else-before返回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;
如果您可以发布一个指向jsfiddle.net示例的链接,或者发布使用此jquery代码片段的html文档,或者告诉我们它有什么问题,这会有所帮助吗?可能是一条错误消息?我添加了html,但我真的觉得这只是一个语法错误…缺少}或放错了地方;如果我知道问题是什么,我现在就不会在这里了……对不起,但这个问题很可能会被解决。你甚至没有告诉我们这段代码到底应该做什么。此外,即使你没有经验,也欢迎你做出一些努力。喜欢问如何调试代码,而不是让别人替你做你的工作。非常感谢杰夫!这非常有帮助!其他人:这么难吗???