拜托,某人,任何人。我过去几天一直在讨论JQuery验证问题。我尝试了各种各样的东西,甚至从头开始几次。这是我最近的迭代,使用下面的链接作为参考。我做错了什么?!
它到达此行并停止:var validator = new jQueryValidatorWrapper(“#formRegister”,rules,messages);
http://www.codeproject.com/KB/ajax/jQueryValidateExample.aspx
HTML
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="register.aspx.cs" Inherits="Website.Pages.register" %>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js" type="text/javascript"></script>
<link href="../Styles/registration.css" rel="stylesheet" type="text/css" />
<script src="../Scripts/val.js" type="text/javascript"></script>
<script src="../Scripts/_plugins/validate.js" type="text/javascript"></script>
<div class="page">
<form runat="server" id="formRegister"><div>
<span id="Run">Username</span><br />
<asp:TextBox runat="server" ID="rUsername" name="rUsername" /></div>
<div><span id="Re">Email</span><br />
<asp:TextBox runat="server" ID="rEmail" name="rEmail" /></div>
<div><span id="Rce">Confirm Email</span><br />
<asp:TextBox runat="server" ID="rConfirmEmail" /></div>
<div><span id="Rpw">Password</span><br />
<asp:TextBox runat="server" ID="rPassword" TextMode="Password" /></div>
<div><span id="Rcpw">Confirm Password</span><br />
<asp:TextBox runat="server" ID="rConfirmPassword" TextMode="Password" Class="required" /></div>
<div id="buttonRegister"><input type="button" id="rRegister" value="Register" /></div>
</form>
</div>
JQUERY
$(function () {
// register.aspx
var rules = {
rUsername: {
required: true,
minlength: 3
},
rEmail: {
required: true,
email: true
}
};
var messages = {
rUsername: {
required: "- Required",
minlength: " - Minimum Length: 3"
},
rEmail: {
required: "- Required",
email: "- Incorrect Format"
}
};
$("#rRegister").click(function () {
var validator = new jQueryValidatorWrapper("#formRegister", rules, messages);
if (!validator.validate())
return;
alert("Validation Success!");
});
});
答案 0 :(得分:0)
以上评论是正确的。试试这个:
$("#rRegister").click(function () {
var validator = new jQueryValidatorWrapper("#<%= formRegister.ClientID%>", rules, messages);
if (!validator.validate())
return;
alert("Validation Success!");
});