【问题标题】:How to create a form input area that will only accept one answer using html如何使用html创建一个只接受一个答案的表单输入区域
【发布时间】:2019-07-23 21:57:12
【问题描述】:

如何使用 HTML 在 <form> 上创建具有特定值的文本输入或密码输入,例如:“apples”,除非将信息输入表单的人输入“apples”,否则表单将不会提交" 进入那个文本(或密码)输入区?

【问题讨论】:

    标签: html forms validation input passwords


    【解决方案1】:
    <html>
    <head>
        <script>
            function get(eId) {return document.getElementById(eId);};
            function verify(eId, eVal) {
                if (eVal !== get(eId).value) {
                    alert('input must contain "' + eVal + '"!');
                    return false;
                }
                else return true;
            };
            function verifySubmit(eId,eVal) {
                if (verify(eId,eVal)) get(eId).parentNode.submit();
            };
        </script>
    </head>
    <body>
        <form action="https://google.com">
            <label>enter "apples": </label><input id="apple" type="text" onchange="verify(this.id,'apples');" /> 
            <input type="button" value="submit" onclick="verifySubmit('apple','apples');" />
        </form>
    </body>
    </html>
    

    【讨论】:

      【解决方案2】:

      确保输入控件是必需的,并使用仅包含单词 apple 的验证模式。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-03-10
        • 2015-09-07
        • 1970-01-01
        • 2020-02-24
        • 1970-01-01
        • 1970-01-01
        • 2019-12-05
        相关资源
        最近更新 更多