【发布时间】:2009-12-14 07:47:16
【问题描述】:
我的网站 (http://www.jakelazaroff.com/#contact) 上有一个表单,我使用 jQuery 提交。表单提交成功的回调函数应该是让表单消失;但是,由于某种原因,这只适用于某些浏览器/操作系统组合。目前,兼容性列表如下:
WORKS
o firefox 3.0, xp
o firefox 3.0.14, vista
o firefox 3.0.15, vista
o firefox 3.5.5, os 10.6.2
v chrome 4.0.249.30, os 10.6.2
o chrome 3.0.195.33, w7
DOESNT WORK
o safari 4.0.4, os 10.6.2
o safari 4.0.3, os 10.5.8
o firefox 3.5.5, w7
o firefox 3.5.5, os 10.5.8
o chrome 3.0.195.33, vista
o = unreproduced, v = reproduced, x = conflicting
...这是一个奇怪的列表(它适用于 Mac OS 10.6.2 上的 Firefox 3.5.5,但不适用于 Mac OS 10.5.8 上的 Firefox 3.5.5?)。我用来验证/提交表单的代码和回调函数如下:
// hide the form and display success message (called after form is submitted)
function formHide() {
// cache form wrapper and blurb
var formWrapper = $("#contactForm");
var formBlurb = $("#contact .formBlurb");
// set the height of wrapper and blurb
formWrapper.height(formWrapper.height());
formBlurb.height(formBlurb.height());
// fade out required fields message, fade in success message
formBlurb.find(".requiredFields").fadeOut("fast", function() {
formBlurb.find(".thanks").fadeIn("fast");
});
// fade out form
formWrapper.find("form").fadeOut("slow", function(){
// slide up the div so there's no jump
formWrapper.slideUp("slow");
});
}
// cache the form
var form = $("#contactForm form");
// validate the form
$("#contactForm form").validate({
// when errors are made...
errorPlacement: function() {
// turn the background on those elements red
$("#contactForm form .error").animate( { backgroundColor:"#ff6666" }, "fast" );
},
// when submitting the form...
submitHandler: function(form){
$(form).ajaxSubmit({
// use fm.pl as the submission script
url: "cgi-bin/fm.pl",
// hide the form if it's successful
success: formHide
});
}
});
我使用的表单插件可以在http://malsup.com/jquery/form/找到,我使用的验证插件可以在http://bassistance.de/jquery-plugins/jquery-plugin-validation/找到。有什么我遗漏的东西破坏了兼容性吗?
谢谢:)
附: 抱歉,我没有将我使用的插件的 URL 格式化为链接 - 在我获得 10 个声望点之前,我不能发布多个链接。
附言好的,发布这个给了我 10 个额外的声誉点,所以我正在使用的插件的 URL 现在是链接。
【问题讨论】:
-
+1 也可以获得 10 分 :) 现在您可以编辑您的帖子了!
标签: javascript jquery jquery-plugins jquery-validate jquery-forms-plugin