简体   繁体   English

JS表单验证不在IE中工作

[英]JS form validation not working in IE

Simple JS form validation does not seem to be working in IE. 简单的JS表单验证似乎在IE中不起作用。 Any help would be grand. 任何帮助都会很棒。 It seems to be submitting the form rather then giving me an alert when nothing is entered into the email field. 它似乎是在提交表单而不是在电子邮件字段中没有输入任何内容时给我提醒。 works as intended in Chrome, FF, Opera, Safari, Just NOT in IE. 适用于Chrome,FF,Opera,Safari,而不是IE浏览器。

HTML HTML

<form action="index.php" name="loginForm" onsubmit="return validateLoginForm();" method="post" >
    <div class="formBg">
      <input type="text" name="email" id="email" tabindex="1" class="formPos" value="" placeholder="Email" />
      <div class="loginText"><a href="#" class="linkOne">Forgot your password?</a></div>
    </div>
    <div class="formBg">
      <input type="password" name="password" id="password" tabindex="2" class="formPos" value="" placeholder="Password" />
      <div class="loginText">Keep me logged in</div>
    </div>
    <div id="loginBtnFrame">
      <div id="loginBtn">
        <input type="submit" name="submit" id="loginFormBtn" value=" " tabindex="3" />
      </div>
      <div class="slider-frame"><span class="slider-button">no</span></div>
      <input type="checkbox" value="1" id="rememberMe" name="rememberMe" />
    </div>
  </form>

Javascript 使用Javascript

function validateLoginForm()
{
var x=document.forms["loginForm"]["email"].value;
if (x==null || x=="")
  {
  alert("email must be filled out");
  return false;
  }
}

Thank you so much in advance. 非常感谢你提前。

For those that may hit the same issue. 对于那些可能遇到同样问题的人。

I found that IE simple form validation conflicts with HTML or some Jquery 'placeholders'. 我发现IE简单表单验证与HTML或一些Jquery'占位符'冲突。 I got around it by adding '(x==null || x=="" || x=="Email")' to the JS command. 我通过在JS命令中添加'(x == null || x ==“”|| x ==“Email”)'来解决这个问题。 Where 'Email' is the placeholder text. “电子邮件”是占位符文本的位置。 Now working as intended. 现在按预期工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM