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

Instant validation with JavaScript - not sure where to start

本文关键字:不确定 开始 验证 JavaScript 使用      更新时间:2023-09-26

//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>