简体   繁体   English

如何在单个页面上检查多个表单上的必填字段?

[英]How do I check required fields on multiple forms on a single page?

I have a page that contains the following: 我的页面包含以下内容:

<!DOCTYPE html>
    <html>
        <body>

        <form action="demo_form.asp">
          Username: <input type="text" name="usrname" required>
        </form>

        <div class="map"></div>
        <div><p>Some content to explain some things</p></div

        <form action="demo_form.asp">
          Username: <input type="text" name="lastusrname" required>
          <input type="submit">
        </form>

        <p><strong>Note:</strong> The required attribute of the input tag is not supported in Internet Explorer 9 and earlier versions, or in Safari.</p>

    </body>
</html>

When you click SUBMIT, it only checks the 2nd form where the input submit is included. 当您单击“提交”时,它仅检查包含输入提交的第二个表单。 I assume I will need to write some JQuery or Javascript function to check if all the required fields are filled out? 我假设我将需要编写一些JQuery或Javascript函数来检查是否填写了所有必填字段?

The reason for two forms is that I have other html between the forms 两种形式的原因是在两种形式之间我还有其他html

The reason for two forms is that I have other html between the forms 两种形式的原因是在两种形式之间我还有其他html

You can embed other HTML within a form - try it. 可以在表单中嵌入其他HTML-试试吧。 The existence of two FORM elements is what's breaking your form submission. 两个FORM元素的存在正在破坏您的表单提交。

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

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