• <tfoot id='zQV0R'></tfoot>

    1. <i id='zQV0R'><tr id='zQV0R'><dt id='zQV0R'><q id='zQV0R'><span id='zQV0R'><b id='zQV0R'><form id='zQV0R'><ins id='zQV0R'></ins><ul id='zQV0R'></ul><sub id='zQV0R'></sub></form><legend id='zQV0R'></legend><bdo id='zQV0R'><pre id='zQV0R'><center id='zQV0R'></center></pre></bdo></b><th id='zQV0R'></th></span></q></dt></tr></i><div id='zQV0R'><tfoot id='zQV0R'></tfoot><dl id='zQV0R'><fieldset id='zQV0R'></fieldset></dl></div>
      • <bdo id='zQV0R'></bdo><ul id='zQV0R'></ul>

    2. <legend id='zQV0R'><style id='zQV0R'><dir id='zQV0R'><q id='zQV0R'></q></dir></style></legend>

      1. <small id='zQV0R'></small><noframes id='zQV0R'>

        HTML5 气泡消息

        时间:2023-09-30

        <small id='p6eOZ'></small><noframes id='p6eOZ'>

      2. <tfoot id='p6eOZ'></tfoot>
            • <legend id='p6eOZ'><style id='p6eOZ'><dir id='p6eOZ'><q id='p6eOZ'></q></dir></style></legend>

                <i id='p6eOZ'><tr id='p6eOZ'><dt id='p6eOZ'><q id='p6eOZ'><span id='p6eOZ'><b id='p6eOZ'><form id='p6eOZ'><ins id='p6eOZ'></ins><ul id='p6eOZ'></ul><sub id='p6eOZ'></sub></form><legend id='p6eOZ'></legend><bdo id='p6eOZ'><pre id='p6eOZ'><center id='p6eOZ'></center></pre></bdo></b><th id='p6eOZ'></th></span></q></dt></tr></i><div id='p6eOZ'><tfoot id='p6eOZ'></tfoot><dl id='p6eOZ'><fieldset id='p6eOZ'></fieldset></dl></div>
                  <tbody id='p6eOZ'></tbody>
                  <bdo id='p6eOZ'></bdo><ul id='p6eOZ'></ul>
                • 本文介绍了HTML5 气泡消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  输入字段必填有一个新的HTML5属性,当提交表单并且该字段为空时会弹出一个气泡消息.有没有办法用不同的文字弹出同一个气泡?我想将它用于不同的验证(不仅仅是它是否为空).

                  There is a new HTML5 attribute for input field required which pops up a bubble message when submitting form and the field is empty. Is there any way of popping up the same bubble with different text? I want to use it for different validations (not just if it's empty or not).

                  这是 Chrome 中此气泡(弹出窗口)的屏幕截图:

                  Here is a screenshot on this bubble (pop-up) in Chrome:

                  推荐答案

                  HTML5 提供了一个名为 setCustomValidity 来实现这一点.此方法是一个低级 API,用于添加新的验证约束和添加新的/更改错误消息.您必须调用您的脚本,该脚本会删除/添加验证消息 - 使用 setCustomValidity -(在DOMready"上和)输入/更改.

                  HTML5 provides a method called setCustomValidity to achieve exactly this. This method is a low level API to add new validation constraints and to add new/change errormessages. You have to call your script, which removes / adds the validation message - using setCustomValidity - (on "DOMready" and) on input/change.

                  我写了一个polyfill脚本,它不仅在所有浏览器中实现了那些HTML5表单方法,还添加了一个"customValidity"-helper,这使得使用自定义消息添加自定义验证约束变得更加容易.

                  I have written a polyfill script, which not only implements those HTML5 form methods in all browsers, but also adds a "customValidity"-helper, which makes it more easy to add custom validation constraints with custom messages.

                  注意:您无需实现 webshims 库即可使用此脚本.它也可以在没有 webshims 库的情况下工作.(但如果您使用 webshims lib,您将在包括 IE6 在内的所有浏览器中获得约束验证).如果您不想拥有这个跨浏览器,只需使用 有效性帮助脚本.文档在这里.

                  Note: You don't need to implement webshims lib to make use of this script. It also works without webshims lib. (But if you use webshims lib, you will get constraint validation in all browsers including IE6). If you don't want to have this cross-browser, simply take only the validity-helper script. Documentation is here.

                  请注意,如果您确实通过设置自定义消息对消息进行了更改,则必须包含一种清除消息的方法,例如

                  Note that if you do make a change to the message by setting a custom message, you have to include a way to clear the message such as

                  myFormElement.setCustomValidity('');

                  myFormElement.setCustomValidity('');

                  如果您不清除消息,表单元素将被视为无效,表单将不会提交.

                  if you don't clear the message, the form element will be seen as invalid and the form will not submit.

                  这篇关于HTML5 气泡消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:处理弹出关闭的正确方法 下一篇:JavaScript 中弹出窗口的回调

                  相关文章

                  <tfoot id='f3ebs'></tfoot>

                  1. <legend id='f3ebs'><style id='f3ebs'><dir id='f3ebs'><q id='f3ebs'></q></dir></style></legend>
                    1. <small id='f3ebs'></small><noframes id='f3ebs'>

                        <bdo id='f3ebs'></bdo><ul id='f3ebs'></ul>
                    2. <i id='f3ebs'><tr id='f3ebs'><dt id='f3ebs'><q id='f3ebs'><span id='f3ebs'><b id='f3ebs'><form id='f3ebs'><ins id='f3ebs'></ins><ul id='f3ebs'></ul><sub id='f3ebs'></sub></form><legend id='f3ebs'></legend><bdo id='f3ebs'><pre id='f3ebs'><center id='f3ebs'></center></pre></bdo></b><th id='f3ebs'></th></span></q></dt></tr></i><div id='f3ebs'><tfoot id='f3ebs'></tfoot><dl id='f3ebs'><fieldset id='f3ebs'></fieldset></dl></div>