jQuery.validationEngine引用错误?

时间:2013-11-14 19:40:24

标签: javascript jquery html5 jquery-plugins

似乎所有东西都被正确引用但是我无法让它正常工作。奇怪的是它工作了一次但是在验证消息弹出之前花了10秒钟,没有改变任何东西并再次尝试但是停止工作。我唯一的警告是jQuery库中的event.returnValue is deprecated. Please use the standard event.preventDefault() instead.

<html>

 <head>
<link rel="stylesheet" href="jQuery-Validation-Engine-master/css/validationEngine.jquery.css" type="text/css"/>
   </head>

<body>

    <form id="formID">
        <input class="validate[required]" type="text" id="agree" name="agree"/>
    </form>

 <script src='js/jquery-1.10.2.min.js'></script>
    <script src="jQuery-Validation-Engine-master/js/languages/jquery.validationEngine-en.js" type="text/javascript" charset="utf-8"></script>
    <script src="jQuery-Validation-Engine-master/js/jquery.validationEngine.js" type="text/javascript" charset="utf-8"></script>

    <script>
        $(document).ready(function(){
            $("#formID").validationEngine();
        });
    </script>

</body>

如果上面没有任何问题,那么我的项目可能会干扰其他内容,但任何帮助都会受到赞赏。

2 个答案:

答案 0 :(得分:0)

正在发生的事情可能是,当jQuery加载时你的插件尚未加载,所以当你调用validationEngine()方法时,它尚未定义。我建议与Modernizr同步加载脚本,并在两个脚本加载后调用该方法。

如果您坚持使用Modernizr方式,您只需将最小化的Modernizr版本包含在头部并调用脚本,如下所示。

<!doctype html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Your Document</title>
        <!--
            following script loads first. nevermind the version, I copied it from a script of mine
        -->
        <script type="text/javascript" src="js/modernizr.2.6.2.min.js"></script>
    </head>

    <body>
        <form id="formID">
            <!-- etc -->
        </form>
        <script type="text/javascript">
            Modernizr.load([
            {
                // following loads next
                load: 'http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js',
                complete: function() {
                    if (!window.jQuery) Modernizr.load('js/jquery-1.10.2.min.js');
                    // this is your local copy of jQuery, in case you might need a fallback
                }
            },{
                // finally the remaining scripts load
                load:[
                    'jQuery-Validation-Engine-master/js/languages/jquery.validationEngine-en.js',
                    'jQuery-Validation-Engine-master/js/jquery.validationEngine.js'
                ],
                complete: function() {
                    // all is loaded. do what you want here.
                    $("#formID").validationEngine();
                }
            }]);
        </script>
    </body>
</html>

答案 1 :(得分:0)

在我的案例中,正如我上面提到的,更新到jQuery lib 1.11.0为我发出警告。 (最新的铬)

如果感兴趣的话,我最终会使用validationEngine:

<form id="formID" />
<button type="submit" value="Save" id="Save" onclick="clicked(event);">Submit Survey</button>

function clicked (e) 
    {
        if (confirm('Are you sure you want to submit?')) 
        {
           if ($("#formID").validationEngine('validate'))
           {
               my.LocalStorage.save(); 
           }
        }   
        e.preventDefault();  
    }