繁体   English   中英

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

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

我有一个网站的大表单,有多个必填字段,并且所有字段都运行良好,当我单击表单上的提交时,网页滚动到该字段的位置并显示一条错误消息,除了两个部分,“旅客人数”和“旅行日期”。 这是他们两个的 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>

这是指向正在运行的页面的链接: http : //www.eliteware.co/92/form/

您的按钮不可聚焦,因为您试图在它必须再次获得焦点时将其隐藏。 查看以下链接,了解有关发生这种情况的原因的更多信息。 基本上,您隐藏了在需要验证时应该获得焦点的对象。 如果您不希望发生这种情况,您可以在隐藏之前进行验证,或者在验证失败时取消隐藏对象。

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

另外,请记住,如果存在错误日志,这是检查您是否收到错误的第一点。 这就是错误日志的全部内容,为您提供调试的起点。

或者正如 Andreas 所说,“修复控制台中该死的错误...... :)”。

编辑:

因为它让我很伤心,所以我试图对您的应用程序进行逆向工程。 所需要的只是比较正在工作的文本框和未能找到问题的文本框。 真的,那么容易。

aria-required="true"

您的“成人”和“儿童”输入字段具有此属性。 您需要required="true"代替。

检查您的 css 并更新它。 不,我不知道为什么“aria=required”和“required”属性的行为不同。 这肯定是学习新的东西。

暂无
暂无

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

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