Javascript 为什么赢了';我的jQuery验证代码在浏览器中运行时不能工作吗?
它在jsfiddle中工作。我不明白当我在浏览器中运行它时为什么它不工作。我能想到的唯一一件事是,我可能错误地链接了jquery文件/链接了错误的文件。不过我试过很多。基本上,我在jquery网站上下载jquery,链接它(它在同一个文件夹中)。我也尝试了具体的验证,但没有成功。现在我正在使用在JSFIDLE中工作的链接。请帮忙(Javascript 为什么赢了';我的jQuery验证代码在浏览器中运行时不能工作吗?,javascript,jquery,validation,Javascript,Jquery,Validation,它在jsfiddle中工作。我不明白当我在浏览器中运行它时为什么它不工作。我能想到的唯一一件事是,我可能错误地链接了jquery文件/链接了错误的文件。不过我试过很多。基本上,我在jquery网站上下载jquery,链接它(它在同一个文件夹中)。我也尝试了具体的验证,但没有成功。现在我正在使用在JSFIDLE中工作的链接。请帮忙( 您需要包括jQuery库 <!DOCTYPE html> <html> <head> <
您需要包括jQuery库
<!DOCTYPE html>
<html>
<head>
<title>JQ</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.js"></script><!--Include jQuery before includign the plugin-->
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.13.1/jquery.validate.min.js"></script>
<script src="validate.js"></script>
</head>
<body>
<form id="signupform">Username
<input id="user" name="user" type="text" />
<br/>
<button type="submit">Submit</button>
</form>
</body>
</html>
JQ
用户名
提交
啊,您编辑的代码现在可以工作了,谢谢!我以为它们的顺序是正确的,我猜不是。但是谢谢,我对此感到沮丧了很久,但修复方法很简单。
$(document).ready(function () {
$("#signupform").validate({
rules: {
user: {
required: true,
minlength: 4
}
},
messages: {
user: {
required: "please enter a username",
minlength: "Your username must be at least 4 characters long"
}
}
});
});
<!DOCTYPE html>
<html>
<head>
<title>JQ</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.js"></script><!--Include jQuery before includign the plugin-->
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.13.1/jquery.validate.min.js"></script>
<script src="validate.js"></script>
</head>
<body>
<form id="signupform">Username
<input id="user" name="user" type="text" />
<br/>
<button type="submit">Submit</button>
</form>
</body>
</html>