JQuery 验证让我抓狂?

发布于 2024-12-19 06:05:01 字数 2647 浏览 1 评论 0原文

拜托,某人,任何人。最近几天我一直遇到 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>

查询

$(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!");
});

});

Please, someone, anyone. I've been having JQuery validation issues for the last few days. I've tried all kinds of things and even started from scratch a few times. This is my latest iteration using the link below as reference. What am I doing wrong?!

It gets to this line and stops: 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!");
});

});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

埖埖迣鎅 2024-12-26 06:05:01

上面的评论是正确的。试试这个:

$("#rRegister").click(function () {
    var validator = new jQueryValidatorWrapper("#<%= formRegister.ClientID%>", rules, messages);
    if (!validator.validate())
        return;

    alert("Validation Success!");
});

The comments above are correct. Try this:

$("#rRegister").click(function () {
    var validator = new jQueryValidatorWrapper("#<%= formRegister.ClientID%>", rules, messages);
    if (!validator.validate())
        return;

    alert("Validation Success!");
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文