简体   繁体   English

HTML验证似乎不起作用

[英]html validation doesn't seem to be working

I'm using validation on fields, which need to be entered before a user is to log in. However, I'm encountering a problem. 我在字段上使用验证,需要在用户登录之前输入。但是,我遇到了问题。 I'm using the required tags within the html input tags but when a user clicks on the login button, there is no message telling them that the fields are required. 我在html输入标签中使用了所需的标签,但是当用户点击登录按钮时,没有消息告诉他们这些字段是必需的。

I have been researching on w3Schools 我一直在研究w3Schools

Which states the use of required will proc a message when the field is empty, if the user tries to click submit without the user entering the required fields. 其中指出,如果用户在没有用户输入必填字段的情况下尝试单击“提交”,则在字段为空时使用required将触发消息。

Any suggestions? 有什么建议么?

 <div class="tab-pane fade show" id="profile" role="tabpanel" aria-labelledby="profile-tab"> <br /> <h3 style='color: #fff;' class="register-heading">Log in to view your <span style='font-weight: bold;'>dashboard</span></h3> <div class="row register-form"> <div class="col-md-12"> <div class="form-group"> <input id="login-email" type="email" class="form-control" placeholder="Email *" value="" required/> </div> </div> <div class="form-group col-md-12"> <input id="login-password" type="password" class="form-control" placeholder="Password *" value="" required /> </div> <div class="col-md-2"></div> <div class="col-md-6"> <input class="btnRegister pull-left" id="login-btn" type="submit" value="Login"/> </div> <div class="col-md-4"></div> </div> </div> 

You're not using a <form> therefore, the button does not know where to 'submit' too. 因此,您没有使用<form> ,该按钮也不知道“提交”的位置。 See this working example. 见这个工作示例。

 <form> <div class="tab-pane fade show" id="profile" role="tabpanel" aria-labelledby="profile-tab"> <br /> <h3 style='color: #fff;' class="register-heading">Log in to view your <span style='font-weight: bold;'>dashboard</span></h3> <div class="row register-form"> <div class="col-md-12"> <div class="form-group"> <input id="login-email" type="email" class="form-control" placeholder="Email *" value="" required/> </div> </div> <div class="form-group col-md-12"> <input id="login-password" type="password" class="form-control" placeholder="Password *" value="" required /> </div> <div class="col-md-2"></div> <div class="col-md-6"> <input class="btnRegister pull-left" id="login-btn" type="submit" value="Login" /> </div> <div class="col-md-4"></div> </div> </div> </form> 

For the required attribute to work, your input tags need to be within form tags: 要使所需的属性起作用,输入标记必须位于表单标记内:

 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> <div class="tab-pane fade show" id="profile" role="tabpanel" aria-labelledby="profile-tab"> <br /> <h3 style='color: #fff;' class="register-heading">Log in to view your <span style='font-weight: bold;'>dashboard</span></h3> <div class="row register-form"> <form> <div class="col-md-12"> <div class="form-group"> <input id="login-email" type="email" class="form-control" placeholder="Email *" value="" required/> </div> </div> <div class="form-group col-md-12"> <input id="login-password" type="password" class="form-control" placeholder="Password *" value="" required /> </div> <div class="col-md-2"></div> <div class="col-md-6"> <input class="btnRegister pull-left" id="login-btn" type="submit" value="Login" /> </div> <div class="col-md-4"></div> </form> </div> </div> 

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

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