javascript - 使用 JavaScript 进行即时验证 - 不确定从哪里开始

标签 javascript jquery html css email-validation

//PENDING
body {
  font-family: "Raleway", sans-serif;
  font-size: 14pt;
  /* 1em */
  color: white;
  text-align: center;
  background-image: url(./img/bg);
}
#cog {
  margin-top: 5%;
  margin-bottom: -5%;
}
section.hero {
  padding: none;
  margin-left: 10%;
  margin-right: 10%;
}
section.hero h1.heroText {
  font-size: 3em;
  font-weight: 100;
}
section.hero h1.subText {
  font-size: 1.5em;
  font-weight: 100;
}
div.footer {
  font-size: 1.75em;
  font-weight: 100;
  position: absolute;
  bottom: 5px;
  width: 100%;
  text-align: center;
}
input.nicerInput {
  height: 50px;
  width: 25%;
  outline: none;
  background-color: white;
  color: #aaa;
  font-size: 1em;
  text-align: center;
  font-family: "Raleway", sans-serif;
  font-weight: 100;
  display: inline-block;
}
input.submitButton {
  color: white;
  font-family: "Raleway", sans-serif;
  font-weight: 100;
  font-size: 1em;
  height: 56px;
  width: 150px;
  background-color: #5CCF58;
  text-decoration: none;
  text-align: center;
  outline: none;
  border: none;
  display: inline-block;
  position: relative;
  left: -6px;
  top: -1px;
  -webkit-transition: linear all 1s;
  -moz-transition: linear all 1s;
  -mos-transition: linear all 1s;
}
input.submitButton:hover {
  color: inherit;
  background-color: #28CD20;
  -webkit-transition: linear all 0.5s;
  -moz-transition: linear all 0.5s;
  -mos-transition: linear all 0.5s;
}
input.submitButton:active {
  color: inherit;
  background-color: #21B71C;
  -webkit-transition: linear all 0.1s;
  -moz-transition: linear all 0.1s;
  -mos-transition: linear all 0.1s;
}
.errorMsg {
  color: white;
  font-size: 1em;
  margin-left: 10%;
  margin-right: 10%;
  display: none;
}
.fa-spin-custom {
  -webkit-animation: spin 7500ms infinite linear;
  animation: spin 7500ms infinite linear;
}
@-webkit-keyframes spin {
  0% {
    -webkit-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(359deg);
    transform: rotate(359deg);
  }
}
@keyframes spin {
  0% {
    -webkit-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(359deg);
    transform: rotate(359deg);
  }
}
.fa-7x {
  font-size: 7.5em !important;
}
<!DOCTYPE HTML>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1, user-scalable=no, width=device-width">
  <meta name="author" content="Olly John">
  <meta name="keywords" content="Stephen John Eyecare, Stephen John Opticians, Worcester, Opticians, Opticions">
  <link rel="stylesheet" type="text/css" href="./css/normalize.css">
  <link rel="stylesheet" type="text/css" href="./css/styles.css">
  <link href='http://fonts.googleapis.com/css?family=Raleway:400,100' rel='stylesheet' type='text/css'>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
  <title>Stephen John Eyecare - Coming Soon</title>
</head>

<body>
  <i class="fa fa-7x fa-cog fa-spin-custom" id="cog"></i>
  <section class="hero">
    <h1 class="heroText">We'll be coming <strong>really soon!</strong></h1>
    <h1 class="subText">If you'd like to be notified when we go live, please submit your e-mail address using the field below</h1>
  </section>
  <section class="field">
    <form action="" name="form" method="post">
      <div class="form">
        <input type="text" class="nicerInput" name="input" id="input" placeholder="you@youremail.com">
        <input type="submit" class="submitButton" disabled="true" value="submit" id="sub">
        <br>
        <br>
        <span class="errorMsg" id="empty">Please make sure to enter your e-mail address before submitting it to us. <br></span>
        <span class="errorMsg" id="format">The e-mail address you entered is invalid.  Please enter an e-mail address in the format johndoe@email.com</span>
      </div>
    </form>
  </section>
  <div class="footer">Stephen John Eyecare</div>
  <script src="bower_components/jquery/src/jquery.js"></script>
  <!-- Use jQuery to validate?-->
</body>

</html>

大家好,

我父亲要求我为他正在制作的网站制作一个登陆页面,他只是想把一些东西放在主机上,这样它就不会被浪费,因为他已经购买了空间和域名,但是有一个网站的开发遇到了挫折,所以他只是让我快速制作一些东西,说明主网站即将推出,并让人们能够注册,以便在网站上线时收到通知。
我已经完成了所有的前端工作,并且已经开始研究“表单”的验证方面,但我无法弄清它的正面或反面,所以我希望有人可以提供一些关于我的见解需要为它做,如果你会这么好心。
目前该页面的代码在代码段中。

提前致谢

最佳答案

使用下面的代码,它将进行验证。不要忘记放置主 jquery 并验证 min 文件

<!DOCTYPE HTML>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1, user-scalable=no, width=device-width">
  <meta name="author" content="Olly John">
  <meta name="keywords" content="Stephen John Eyecare, Stephen John Opticians, Worcester, Opticians, Opticions">
  <link rel="stylesheet" type="text/css" href="./css/normalize.css">
  <link rel="stylesheet" type="text/css" href="./css/styles.css">
  <link href='http://fonts.googleapis.com/css?family=Raleway:400,100' rel='stylesheet' type='text/css'>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
  <title>Stephen John Eyecare - Coming Soon</title>
  <style>
  body {
  font-family: "Raleway", sans-serif;
  font-size: 14pt;
  /* 1em */
  color: #000;
  text-align: center;
  background-image: url(./img/bg);
}
#cog {
  margin-top: 5%;
  margin-bottom: -5%;
}
section.hero {
  padding: none;
  margin-left: 10%;
  margin-right: 10%;
}
section.hero h1.heroText {
  font-size: 3em;
  font-weight: 100;
}
section.hero h1.subText {
  font-size: 1.5em;
  font-weight: 100;
}
div.footer {
  font-size: 1.75em;
  font-weight: 100;
  position: absolute;
  bottom: 5px;
  width: 100%;
  text-align: center;
}
input.nicerInput {
  height: 50px;
  width: 25%;
  outline: none;
  background-color: white;
  color: #aaa;
  font-size: 1em;
  text-align: center;
  font-family: "Raleway", sans-serif;
  font-weight: 100;
  display: inline-block;
}
input.submitButton {
  color: white;
  font-family: "Raleway", sans-serif;
  font-weight: 100;
  font-size: 1em;
  height: 56px;
  width: 150px;
  background-color: #5CCF58;
  text-decoration: none;
  text-align: center;
  outline: none;
  border: none;
  display: inline-block;
  position: relative;
  left: -6px;
  top: -1px;
  -webkit-transition: linear all 1s;
  -moz-transition: linear all 1s;
  -mos-transition: linear all 1s;
}
input.submitButton:hover {
  color: inherit;
  background-color: #28CD20;
  -webkit-transition: linear all 0.5s;
  -moz-transition: linear all 0.5s;
  -mos-transition: linear all 0.5s;
}
input.submitButton:active {
  color: inherit;
  background-color: #21B71C;
  -webkit-transition: linear all 0.1s;
  -moz-transition: linear all 0.1s;
  -mos-transition: linear all 0.1s;
}
.errorMsg {
  color: white;
  font-size: 1em;
  margin-left: 10%;
  margin-right: 10%;
  display: none;
}
.fa-spin-custom {
  -webkit-animation: spin 7500ms infinite linear;
  animation: spin 7500ms infinite linear;
}
@-webkit-keyframes spin {
  0% {
    -webkit-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(359deg);
    transform: rotate(359deg);
  }
}
@keyframes spin {
  0% {
    -webkit-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(359deg);
    transform: rotate(359deg);
  }
}
.fa-7x {
  font-size: 7.5em !important;
}
label .error{color:red;}
  </style>
</head>

<body>
  <i class="fa fa-7x fa-cog fa-spin-custom" id="cog"></i>
  <section class="hero">
    <h1 class="heroText">We'll be coming <strong>really soon!</strong></h1>
    <h1 class="subText">If you'd like to be notified when we go live, please submit your e-mail address using the field below</h1>
  </section>
  <section class="field">
    <form action="" name="form"  id="sample_frm" method="post">
      <div class="form">
        <input type="text" class="nicerInput" name="user_email" id="input" placeholder="you@youremail.com">
        <input type="submit" class="submitButton" value="submit" id="sub">
         </div>
    </form>
  </section>
  <div class="footer">Stephen John Eyecare</div>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
  <script src="http://jqueryvalidation.org/files/dist/jquery.validate.min.js"></script>
  
 <script>
  $( "#sample_frm" ).validate({
  rules: {
user_email: {
  required: true,
  email: true
}
  },
  messages:
  {
  user_email:{
  required:"Enter email id", //custom error message
  email: "valid email id"
  }
  }
});
</script>
  <!-- Use jQuery to validate?-->
</body>

</html>

关于javascript - 使用 JavaScript 进行即时验证 - 不确定从哪里开始,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29196185/

相关文章:

javascript - React 应用程序和用户角色

javascript - 为什么放置 div 标签可以让此 React 代码编译?

javascript - 使用 HTML 文本字段沿 SVG textPpath 更新文本

javascript - PreventDefault 不适用于焦点事件

javascript - 一次只能选择一个下拉菜单

jquery - 带包装的 Bootstrap 列

javascript - 为什么在 IE 中加载图像不显示在页面的中心底部?

javascript - Node 获取响应为 503,其中请求响应为代理后面的 200

javascript - 使用 Jquery 的 onClick 事件

Javascript Canvas 未显示