简体   繁体   English

HTML 必填字段在未填写时不显示消息

[英]HTML required fields are not showing a message when it's not filled out

I have a big form for a website, with multiple required fields, and all of them are working perfectly, when i click submit on the form, the web page scroll to the field's location with an error message, except on two parts, the "Number of travelers" and the "Date of the trip".我有一个网站的大表单,有多个必填字段,并且所有字段都运行良好,当我单击表单上的提交时,网页滚动到该字段的位置并显示一条错误消息,除了两个部分,“旅客人数”和“旅行日期”。 This is the HTML for both of them:这是他们两个的 HTML:

<div class="sect-txt" style="margin-top:100px;" id="op">
 <h1> Date of the trip </h1>
 <div class="al">
  <h1 style="font-family:Montserrat;font-size:14px;color:#161616;margin-bottom:5px;"> Check In </h1> 
  <input type="date" class="hide-replaced" data-date-size="1" placeholder="Check-in" name="checkin" required />
 </div>
 <div class="al">
  <h1 style="font-family:Montserrat;font-size:14px;color:#161616;margin-bottom:5px;"> Check Out </h1> 
  <input type="date" class="hide-replaced" data-date-size="1" placeholder="Check-out" name="checkout" required />
 </div>
 <a href="#four">
  <div class="btn-nxt" style="position:relative;top:137px;">
   NEXT
  </div>
 </a>
</div>

<div class="sect-txt">
 <h1> Number of travelers </h1>
 <input type="number" class="f-2" placeholder="Adults" name="adults" required/>
 <input type="number" class="f-3" placeholder="Children" name="childrens" required/>
 <a href="#fif">
  <div class="btn-nxt-b">
   NEXT
  </div>
 </a>
</div>

And this is a link to the page in action: http://www.eliteware.co/92/form/这是指向正在运行的页面的链接: http : //www.eliteware.co/92/form/

Your button is not focusable because you are trying to hide it when it has to receive focus again.您的按钮不可聚焦,因为您试图在它必须再次获得焦点时将其隐藏。 Check the following link for more information about why this happens.查看以下链接,了解有关发生这种情况的原因的更多信息。 Basically, you are hiding the object that is supposed to receive focus when validation is needed.基本上,您隐藏了在需要验证时应该获得焦点的对象。 If you don't want this to happen, you can probably do validation before hiding, or unhide the object if validation fails.如果您不希望发生这种情况,您可以在隐藏之前进行验证,或者在验证失败时取消隐藏对象。

https://stackoverflow.com/a/28340579/616813 https://stackoverflow.com/a/28340579/616813

Also, do remember, if an error log exists, that is the first point to check if you receive an error.另外,请记住,如果存在错误日志,这是检查您是否收到错误的第一点。 That is the whole point of error log, to give you a starting point to debug.这就是错误日志的全部内容,为您提供调试的起点。

Or as Andreas said, "Fix the damn errors in the console... :)".或者正如 Andreas 所说,“修复控制台中该死的错误...... :)”。

Edit:编辑:

Because it was killing me, I tried to reverse engineer your application.因为它让我很伤心,所以我试图对您的应用程序进行逆向工程。 All it took was comparing the textbox that was working, and the one that was failing to find the problem.所需要的只是比较正在工作的文本框和未能找到问题的文本框。 Really, that easy.真的,那么容易。

aria-required="true"

Your "Adults" and "Children" input fields have this property.您的“成人”和“儿童”输入字段具有此属性。 You need required="true" instead.您需要required="true"代替。

Check your css and update that.检查您的 css 并更新它。 And no, I have no idea why "aria=required" and "required" property behave differently.不,我不知道为什么“aria=required”和“required”属性的行为不同。 It is something new to learn for sure.这肯定是学习新的东西。

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

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