我的网站 ( 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/找到. 我缺少什么破坏兼容性的东西吗?
谢谢 :)
PS抱歉,我没有将我使用的插件的 URL 格式化为链接 - 在我获得 10 个声望点之前,我不能发布多个链接。
PPS 好的,发布这个给了我 10 更多的声誉点,所以我正在使用的插件的 URL 现在是链接。