jquery中的错误消息 [英] Error message in jquery

查看:76
本文介绍了jquery中的错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





请查看下面的代码,我想使用jquery显示错误消息,我已经在jquery中为确认密码编写了代码。问题是当txtpwd2控件上发生blur()事件时,我附加了错误消息。但是当我多次创建模糊事件时,错误信息会多次附加。



Hi,

Please look into the code below, i want to display an error message using jquery, i have written code for that in jquery for confirm password. The problem is when blur() event occurs on txtpwd2 control, i am appending the error message. but when i create blur event multiple times, the error message is appending multiple times.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="Scripts/jquery-2.0.2.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {

            $('#txtpwd2').blur(function () {
                debugger;
                var t1 = $('#txtpwd1').val();
                var t2 = $('#txtpwd2').val();
                if (t1 != t2) {
                    $('#d2').append($('#txtpwd2').attr('title'));
                    $('#txtpwd2').focus();
                    return false;
                }

            });

        });

    </script>
</head>
<body>
    <form id="form1" runat="server">

    <div>
        <div id="d1">
            <asp:TextBox runat="server" ID="txtpwd1"></asp:TextBox>
        </div>
        <div id="d2">
            <asp:TextBox runat="server" ID="txtpwd2" title="Passwords do not match"></asp:TextBox>
        </div>
        <div id="d3">
            <asp:Button runat="server" ID="btn" Text="submit" />
        </div>
    </div>
    </form>
</body>
</html>

推荐答案

(document).ready(function(){
(document).ready(function () {


('#txtpwd2')。blur(function) (){
调试器;
var t1 =
('#txtpwd2').blur(function () { debugger; var t1 =


('#txtpwd1')。val();
var t2 =
('#txtpwd1').val(); var t2 =


这篇关于jquery中的错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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