Javascript Dreamweaver在JS文件中显示了一个奇怪的语法错误
Dreamweaver在文件中显示错误 jquery.jig.js 文件是这样的Javascript Dreamweaver在JS文件中显示了一个奇怪的语法错误,javascript,ajax,jquery,dreamweaver,Javascript,Ajax,Jquery,Dreamweaver,Dreamweaver在文件中显示错误 jquery.jig.js 文件是这样的 jQuery(document).ready(function(){ $('#contactform').submit(function(){ var action = $(this).attr('action'); $('#submit').attr('disabled','disabled').after('<img src="contact-form/assets/ajax-lo
jQuery(document).ready(function(){
$('#contactform').submit(function(){
var action = $(this).attr('action');
$('#submit').attr('disabled','disabled').after('<img src="contact-form/assets/ajax-loader.gif" class="loader" />');
$("#message").slideUp(750,function() {
$('#message').hide();
$.ajax({
type:"POST",
url: "yourPhpFileURL.php", //put the url of your php file here
data: $('#contactform').serialize(),
success: function(data){
document.getElementById('message').innerHTML = data;
$('#message').slideDown('slow');
$('#contactform img.loader').fadeOut('fast',function(){$(this).remove()});
$('#submit').removeAttr('disabled');
if(data.match('success') != null) $('#contactform').slideUp('slow');
if(data.match('success') != null) $("html,body").animate({
scrollTop: $("#message").offset().top
}, 1000, function(){
});
if(data.match('success') == null) $("html,body").animate({
scrollTop: $("#message").offset().top
}, 1000, function(){
//scroll complete function
});
}
});
});
return false;
});
});
jQuery(文档).ready(函数(){
$('#contactform')。提交(函数(){
var action=$(this.attr('action');
$('#submit').attr('disabled','disabled')。在('')之后;
$(“#消息”).slideUp(750,函数(){
$(“#消息”).hide();
$.ajax({
类型:“POST”,
url:“yourPhpFileURL.php”//将php文件的url放在这里
数据:$('#contactform')。序列化(),
成功:功能(数据){
document.getElementById('message').innerHTML=data;
$('#message')。向下滑动('slideDown');
$('#contactform img.loader').fadeOut('fast',function(){$(this.remove()});
$(“#提交”).removeAttr('disabled');
if(data.match('success')!=null)$('contactform').slideUp('slow');
如果(data.match('success')!=null)$(“html,body”).animate({
scrollTop:$(“#消息”).offset().top
},1000,函数(){
});
if(data.match('success')==null)$(“html,body”).animate({
scrollTop:$(“#消息”).offset().top
},1000,函数(){
//滚动完成功能
});
}
});
});
返回false;
});
});
错误显示在最后一行中,但我无法理解原因。我通过的JSLint语法分析器运行了您的代码,并修复了一些错误等。到目前为止,下面的验证是正确的。请在您这边核对:
jQuery(document).ready(function() {
$('#contactform').submit(function() {
var action = $(this).attr('action');
$('#submit').attr('disabled', 'disabled').after('<img src="contact-form/assets/ajax-loader.gif" class="loader" />');
$("#message").slideUp(750, function() {
$('#message').hide();
$.ajax({
type: "POST",
url: "yourPhpFileURL.php",
//put the url of your php file here
data: $('#contactform').serialize(),
success: function(data) {
document.getElementById('message').innerHTML = data;
$('#message').slideDown('slow');
$('#contactform img.loader').fadeOut('fast', function() {
$(this).remove();
});
$('#submit').removeAttr('disabled');
if (data.match('success') !== null) {
$('#contactform').slideUp('slow');
}
var msg_offset = $("#message").offset().top;
if (data.match('success') !== null) {
$("html,body").animate({
scrollTop: msg_offset
}, 1000, function() {
});
}
if (data.match('success') === null) {
$("html,body").animate({
scrollTop: msg_offset
}, 1000, function() {
//scroll complete function
});
}
}
});
});
return false;
});
});
jQuery(文档).ready(函数(){
$('#contactform')。提交(函数(){
var action=$(this.attr('action');
$('#submit').attr('disabled','disabled')。在('')之后;
$(“#消息”).slideUp(750,函数(){
$(“#消息”).hide();
$.ajax({
类型:“POST”,
url:“yourPhpFileURL.php”,
//将php文件的url放在这里
数据:$('#contactform')。序列化(),
成功:功能(数据){
document.getElementById('message').innerHTML=data;
$('#message')。向下滑动('slideDown');
$('#contactform img.loader').fadeOut('fast',function(){
$(this.remove();
});
$(“#提交”).removeAttr('disabled');
if(data.match('success')!==null){
$('#contactform')。slideUp('slow');
}
var msg#u offset=$(“#消息”).offset().top;
if(data.match('success')!==null){
$(“html,body”).animate({
scrollTop:msg_偏移量
},1000,函数(){
});
}
if(data.match('success')==null){
$(“html,body”).animate({
scrollTop:msg_偏移量
},1000,函数(){
//滚动完成功能
});
}
}
});
});
返回false;
});
});
文件看起来不错。但是我相信Dreamweaver可能不喜欢你如何编写你的,如果,错误会说什么?仅仅是一个行号?我自己看不到任何主要问题,几个次要问题$('#contactform img.loader').fadeOut('fast',function(){$(this.remove()});在.remove()之后需要一个分号,我会(即使这不应该是任何问题)用大括号重写if语句,并且似乎没有必要测试两次数据。match('success')!=null,然后对该站点进行测试。当然,一个if-else语句就足够了。可能有助于隔离问题错误只是“第40行的语法错误”(最后一行)。。。我不明白为什么。。。如果我删除所有的“如果”,我也会得到同样的错误