开发者

Can jQuery detect if something has been returned false

My predicament is that i have a piece of code that works fine in FF but not in IE. I'm submitting a form and validating it first with jQuery. The problem is that when i fadeIn() a message saying "fields required" its fadeIn() twice because there are two inputs to validate, so in FF this works fine, but in IE, it tries to fade in twice and actually the message appears then disappears straight away. SO what i thought i could do is say "if either returns false then fadeIn message" therefore only doing one fadeIn!

                var name = $("#name").val();
                var email = $("#email").val();
                if (name == ""){
                    $("#needed").fadeIn();
                    return false;   
                }
                if (email == ""){
                 开发者_开发技巧   $("#needed").fadeIn();
                    return false;
                }


why don't you just

if (name == "" || email == ""){
      $("#needed").fadeIn();
      return false;
}


Or

if (!name || !email) {
  var $n = $("#needed") ;
  if ($n.is(":visible")) $n.fadeOut(500); 
  $n.fadeIn (200);
  return false;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜