0

好的,所以我一直在尝试让我的表单验证正常工作,但是我面临着太多的问题。

这是代码:

<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

4

2 回答 2

1

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

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

然后它工作正常

于 2013-11-12T09:18:29.093 回答
0

提交按钮如何?

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

(示例中的按钮)

并且您的站点有一个错误:未捕获的 ReferenceError: jQuery is not defined。js/jquery-1.7.2.min.js <- 在您的服务器上不存在!

于 2013-11-12T09:16:13.740 回答