jQuery $("#form1").validate 不是函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1871424/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
$("#form1").validate is not a function
提问by Steven
<script type="text/javascript">
<!--
$(document).ready(function() {
$("#form1").validate({
rules: {
budget: {
required: true,
minlength:3
} ,
duration: {
required: true,
digits:true
},
town: {
required: true,
minlength:2
},
content: {
required: true,
minlength:300
}
},
messages: {
}
});
});
-->
</script>
Two jquery files are included.
包含两个 jquery 文件。
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="../common/jquery.validate.js"></script>
are included. There is nothing wrong with the inclusion.
被包含在内。包含没有任何问题。
I got an error message
我收到一条错误消息
$("#form1").validate is not a function What's wrong?
$("#form1").validate 不是函数有什么问题?
回答by Jay
Put the jQuery script tag beforethe script tag for validation
将 jQuery 脚本标签放在脚本标签之前进行验证
I just encountered this extremely frustrating error and lost the better part of an hour to it, for lack of a workable answer online. I confirmed in Firebug that I was hitting the CDN for both jQuery and validation.
我刚刚遇到了这个非常令人沮丧的错误,并且由于在线上缺乏可行的答案而浪费了一个小时的大部分时间。我在 Firebug 中确认我正在使用 CDN 进行 jQuery 和验证。
In the end, changing this:
最后,改变这个:
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.7/jquery.validate.min.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.4.4.min.js"></script>
to this:
对此:
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.7/jquery.validate.min.js"></script>
was all I needed.
就是我所需要的。
回答by Michael Sobczak
I had this same issue. It turned out that I was loading the jQuery JavaScript file more than once on the page. This was due to included pages (or JSPs, in my case). Once I removed the duplicate reference to the jQuery js file, this error went away.
我有同样的问题。结果是我在页面上不止一次加载了 jQuery JavaScript 文件。这是由于包含的页面(或 JSP,在我的情况下)。一旦我删除了对 jQuery js 文件的重复引用,这个错误就消失了。
回答by scifisamurai
I had the same issue, and yes I had my jquery included first followed by the jquery validate script. I had no idea what was wrong. Turns out I was using a validate url that had moved. I figured this out by doing the following:
我遇到了同样的问题,是的,我首先包含了 jquery,然后是 jquery 验证脚本。我不知道出了什么问题。原来我正在使用一个已经移动的验证 url。我通过执行以下操作来解决这个问题:
- Open firefox
- Open firebug
- Click the NET tab in firebug. This will show you all the resources that get loaded.
- Load your page.
- Check the loaded resources and see if both your jquery & jquery.validate.js loaded.
- 打开火狐
- 打开萤火虫
- 单击 firebug 中的 NET 选项卡。这将显示所有加载的资源。
- 加载您的页面。
- 检查加载的资源,看看你的 jquery 和 jquery.validate.js 是否都加载了。
In my situation I had a 403 Forbidden error when trying to obtain (http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js which is used in the example on http://rocketsquared.com/wiki/Plugins/Validation).
在我的情况下,我在尝试获取时出现 403 Forbidden 错误(http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js,在http://rocketsquared的示例中使用。 com/wiki/插件/验证)。
Turns out the that link (http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js) had moved to http://view.jquery.com/trunk/plugins/validate/jquery.validate.js(Firebug told me this when I loaded the file locally as opposed to on my web server).
原来那个链接(http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js)已经移到了http://view.jquery.com/trunk/plugins/validate/jquery .validate.js(当我在本地加载文件而不是在我的网络服务器上时,Firebug 告诉我这个)。
NOTE: I tried using microsoft's CDN link also but it failed when I tried to load the javascript file in the browser with the correct url, there was some odd issue going on with the CDN site.
注意:我也尝试使用微软的 CDN 链接,但是当我尝试使用正确的 url 在浏览器中加载 javascript 文件时它失败了,CDN 站点出现了一些奇怪的问题。
回答by Ibrahim
youll need to use the latest http://ajax.microsoft.com/ajax/jquery.validate/1.5.5/jquery.validate.jsin conjunction with one of the Microsoft's CDN for getting your validation file.
您需要将最新的http://ajax.microsoft.com/ajax/jquery.validate/1.5.5/jquery.validate.js与 Microsoft 的 CDN 之一结合使用,以获取您的验证文件。
回答by Josh
Had the same issue; validated HTML & found I was missing a name="email"
attribute from an <input />
. Always validate the HTML to be positiveyour HTML is valid. After I added it, validate()
worked perfectly.
有同样的问题;经过验证的 HTML 并发现我缺少 .html 文件中的一个name="email"
属性<input />
。始终验证 HTML 是肯定的,您的 HTML 是有效的。我添加后,validate()
完美运行。
回答by Ahmad Pouramini
Check if you use Proxy.
检查您是否使用代理。
I've got this problem in Mozilla Firefox, I thought it's some issue related to the Firefox itself. Later I found out that I am using a proxy server. When I unchecked the proxy, everything got fine.
我在 Mozilla Firefox 中遇到了这个问题,我认为这是与 Firefox 本身有关的一些问题。后来我发现我使用的是代理服务器。当我取消选中代理时,一切都很好。
回答by Vismari
Probably the browser first downloaded the validade script and then jQuery. If the validade script be downloaded before loading jQuery you'll get an error. You can see this using a tool like firebug.
可能浏览器首先下载了validade 脚本,然后是jQuery。如果在加载 jQuery 之前下载了验证脚本,您将收到错误消息。您可以使用诸如 firebug 之类的工具来查看这一点。
Try this:
尝试这个:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script>
function LoadValidade() {
var a = false;
try {
var teste = $('*');
if(teste == null)
throw 1;
} catch (e) {
a = true;
}
if (a){
setTimeout(LoadValidade, 300);
return;
}
var validadeScript = document.createElement("script");
validadeScript.src = "../common/jquery.validate.js";
$('head')[0].appendChild(validadeScript);
}
setTimeout(LoadValidade, 300);
</script>
回答by CodeJoust
Make sure that jQuery is using the $ variable, and its not another javascript framework.
确保 jQuery 使用的是 $ 变量,而不是另一个 javascript 框架。
Check your doctype: Validate your html, sometimes browsers don't see stuff in quirks mode, or when they encouter malformed html.
检查您的文档类型:验证您的 html,有时浏览器在 quirks 模式下看不到内容,或者当他们遇到格式错误的 html 时。
Also ensure that jquery.validate.js file is correct.
还要确保 jquery.validate.js 文件是正确的。
You can download it below:
您可以在下面下载:
http://bassistance.de/jquery-plugins/jquery-plugin-validation/
http://bassistance.de/jquery-plugins/jquery-plugin-validation/
回答by Медведев Александр
my solution to the problem:
in footer add <script src="//cdnjs.cloudflare.com/ajax/libs/jquery-form-validator/2.3.26/jquery.form-validator.min.js"></script>
我的问题解决方法:在页脚中添加 <script src="//cdnjs.cloudflare.com/ajax/libs/jquery-form-validator/2.3.26/jquery.form-validator.min.js"></script>
回答by Hamza Amin
In my case i moved the validate part outside of the document ready function and it works fine for me. I hope it would work for u...
在我的情况下,我将验证部分移到了文档就绪功能之外,它对我来说很好用。我希望它对你有用...
$(document).ready(function () {
// paste validate function outside of the document ready function...
});
$('#form1').validate({
rules: {
English_Name: { required: true, minlength: 3 },
Arabic_Name: { required: true, minlength: 3 },
latitude: { required: true, min: 16, max: 32, number: true },
longitude: { required: true, min: 32, max: 52, number: true },
EmployeeID: { required: true },
PaymentTypeID: { required: true },
BusinessTypeID: { required: true },
SalesTypeID: { required: true },
OutletLength: { required: true },
OutletWidth: { required: true },
CONTACT_PERSON: { required: true },
MOBILE_NO: { required: true, minlength: 9, maxlength: 13, digits: true },
TRADE_LIC_DATE: { dateValidation: true },
CreditLimit: { min: 0, max: 2000000 },
CreditPeriod: { min: 0, max: 365 },
EMAIL_ADDRESS: { email: true },
BusinessClassID: { required: true },
CustomerClassificationID: { required: true },
LicenseTypeID: { required: true }
},
message: {
English_Name: {
required: ''
},
ToDate: {
required: ''
}
},
submitHandler: function (form) { // for demo
$.ajax({
type: 'POST',
url: '/sfa/Verification/SaveDataInDatabase',
data: $('form').serialize(),
beforeSend: function () {
$('.submitBtn').attr("disabled", "disabled");
$('.modal-body').css('opacity', '.5');
},
success: function (msg) {
$("#form1").trigger('reset');
$('.modal').modal('hide');
$('.submitBtn').removeAttr("disabled");
$('.modal-body').css('opacity', '');
}
});
}
});