JQuery验证()MVC 4未捕获类型错误对象的翻译:没有方法'验证' [英] jQuery validate() MVC 4 Uncaught Type Error Object [object Object] has no method 'validate'

查看:210
本文介绍了JQuery验证()MVC 4未捕获类型错误对象的翻译:没有方法'验证'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个MVC应用4。我想申请使用jQuery验证某些客户端验证。我不断收到未捕获类型错误:对象[Object对象]没有方法'验证'。我使用的URL链接,而不是在我的项目中的脚本尝试。我检查的脚本,它们确实存在。我拖放脚本到文件,以确保正确地指定的路径。我试过一吨的其他东西,但就是想不通,为什么我收到此错误。

I'm making a a MVC 4 application. I'm trying to apply some client side validation using jQuery validate. I keep receiving "Uncaught Type Error: Object [Object object] has no method 'validate'". I've tried using the url links instead of the scripts in my project. I've checked the scripts, they do exist. I've dragged and dropped the scripts into the file to ensure the path is properly specified. I've tried a ton of other things, but just can't figure out why I'm receiving this error.

下面是我呈现的页面:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>Create</title>
<link href="/Content/site.css" rel="stylesheet"/>

<script src="/Scripts/modernizr-2.5.3.js"></script>

</head>
<body>


<h2>Create Question For d</h2>

<script src="/Scripts/jquery-1.7.1.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.js"></script>
<script src="/Scripts/jquery.validate.unobtrusive.min.js"></script>

<script type="text/javascript"> 
$(document).ready(function () {

    //form validation
    $('#myForm').validate();

    $(':input').rules("add", {
        required: true
    });


    //submit form using jquery
    //$('#myForm').submit(function (event) {

    //    //url-encode the form data
    //    var formData = $(this).serialize();

    //    //post the data to the controller
    //    $.post(
    //        'AddQuestion',
    //        formData
    //        );
    //    event.preventDefault();
    //    handleSuccess();
    //});

    //$(':input').not(':button, :submit, :reset, :hidden').val('');
    //$(':checkbox').attr('checked', false);


    $("input:checkbox").click(function () {
        if ($(this).is(":checked") === true) {
            $('input:checkbox').attr("checked", false);
            $(this).attr("checked", true);
        } else {
            $(this).is(":checked", false);
        }
    });


    //clears form on page load (called from submit function)
    function handleSuccess() {         
        $(':input').not(':button, :submit, :reset, :hidden').val('');
        $(':checkbox').attr('checked', false);
    }
});
</script>


<form action="/Test/AddQuestion" id="myForm" method="post">    <fieldset>
    <legend>Question</legend>
    <!-- input box for question -->
    <input type="text" name="question.query" />

    <h3>Answers</h3>


    <input type="text" name="answer[0].option" /> <input type="checkbox"    name="answer[0].isCorrect" value="true" /> <br />
    <input type="text" name="answer[1].option" /> <input type="checkbox" name="answer[1].isCorrect" value="true"/> <br />
    <input type="text" name="answer[2].option" /> <input type="checkbox" name="answer[2].isCorrect" value="true"/> <br />
    <input type="text" name="answer[3].option" /> <input type="checkbox" name="answer[3].isCorrect" value="true"/> <br />
    <!-- Passes testId & testName to AddQuestion Controller Action -->
    <div>
        <input data-val="true" data-val-number="The field Id must be a number." data-val-required="The Id field is required." id="test_Id" name="test.Id" type="hidden" value="222" />
        <input id="test_name" name="test.name" type="hidden" value="d" />
    </div>

    <p>
        <input type="submit" value="Add Question to Test" />
    </p>
</fieldset>
</form>
<div>
<a href="/Test">Back to List</a>
</div>


<script src="/Scripts/jquery-1.7.1.js"></script>


</body>
</html>

还没有找到一个解决方案。使用标签SRC托管环节都试过了。试着服用标签出来,一次一个,将它们以不同的顺序,他们将在主布局页面,等等...真的难倒就这一个。当然这是令人难以置信的一段简单。

Still have not found a solution. Have tried using hosted links for tag src. Tried taking tags out, one at a time, putting them in different orders, putting them in the master layout page, etc... really stumped on this one. Sure it's sometime unbelievably simple.

推荐答案

figured..you有两个相同的脚本加载页面.. 的jQuery jquery.min ..这是没有必要的..
只是加载min.js,这将被罚款...是T能够始终建议加载在&LT所有js文件; HEAD&GT; 而不是&LT;身体GT; ...

figured..you have two same script loaded in the page..jquery and jquery.min.. which is not necessary at all.. just load min.js and that will be fine... and yes t is always recommended to load all your js file on <head> and not in <body>...

<head>
 <meta charset="utf-8" />
 <meta name="viewport" content="width=device-width" />
 <title>Create</title>
 <link href="/Content/site.css" rel="stylesheet"/>

<script src="/Scripts/modernizr-2.5.3.js"></script>
<script src="/Scripts/jquery-1.7.1.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.js></script>
<script src="/Scripts/jquery.validate.unobtrusive.min.js"></script>
</head>
<body>
..........

这篇关于JQuery验证()MVC 4未捕获类型错误对象的翻译:没有方法'验证'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆