jQuery 表单验证不会引发任何错误

jQuery Form Validation not throwing up any errors

本文关键字:任何 错误 表单 验证 jQuery      更新时间:2023-09-26

好的,所以我一直在尝试让我的表单验证工作,但我遇到了太多问题。

代码如下:

<head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <title>JQuery Validation Engine</title>
    <link rel="stylesheet" href="../css/validationEngine.jquery.css" type="text/css"/>
    <link rel="stylesheet" href="/css/template.css" type="text/css"/>
    <script src="/js/jquery-1.7.2.min.js" type="text/javascript">
    </script>
    <script src="/js/languages/jquery.validationEngine-en.js" type="text/javascript" charset="utf-8">
    </script>
    <script src="/js/jquery.validationEngine.js" type="text/javascript" charset="utf-8">
    </script>
    <script>
        jQuery(document).ready(function(){
            // binds form submission and fields to the validation engine
            jQuery("#formID").validationEngine();
        });
        /**
        *
        * @param {jqObject} the field where the validation applies
        * @param {Array[String]} validation rules for this field
        * @param {int} rule index
        * @param {Map} form options
        * @return an error string if validation failed
        */
        /*function checkHELLO(field, rules, i, options){
            if (field.val() != "HELLO") {
                // this allows to use i18 for the error msgs
                return options.allrules.validate2fields.alertText;
            }
        }
        */
    </script>
</head>
    <div id="test" class="test" style="width:150px;">This is a div element</div>
<form id="formID" class="formular" method="post">
        <fieldset>
            <legend>
                Required!
            </legend>
            <label>
                <span>Field is required : </span>
                <input value="" class="validate[required] text-input" type="text" name="req" id="req" />
            </label>
            <legend>
                Placeholder & required
            </legend>
            <label>
                <span>Field is required : </span>
                <input value="This is a placeholder" data-validation-placeholder="This is a placeholder" class="validate[required] text-input" type="text" name="reqplaceholder" id="reqplaceholder" />
            </label>
            </fieldset>
            </form>
    

来源: http://www.position-absolute.com/articles/jquery-form-validator-because-form-validation-is-a-mess/

从过去 1 小时开始,我一直在努力让这件事工作。我是jQuery的新手,所以无法在这里找到任何问题。

我做错了什么?或者需要添加什么才能使其正常工作?

下面是一个测试网址:http://www.vpsfort.net/test.html

jquery 路径问题,JQuery 没有加载到你的文件中,请在所有 js 文件之前加载

<script src="/js/jquery-1.8.2.min.js" type="text/javascript">

然后它工作正常

提交按钮如何?

<input class="submit" type="submit" value="Validate &amp; Send the form!"/>

(示例中的按钮)

并且您的网站有一个错误:未捕获的引用错误:未定义 jQuery。js/jquery-1.7.2.min.js <- 在您的服务器上不存在!