使用jquery在文本框中进行验证不起作用 [英] Validation in textbox using jquery is not working

查看:68
本文介绍了使用jquery在文本框中进行验证不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script>

    <script type="text/javascript" language="javascript">
        $(document).ready(function ()
        {
            $("#form1").validate({

                rules: {
                    "<%=txtName.ClientID %>": {
                        required: true
                    },
                },
                messages: {
                    "<%=txtName.ClientID %>": {
                        required: "Name should not be empty"
                    },
                }

            });
        });
    </script>

    <style type="text/css">
        label.error {
            color: red;
            display: inline;
        }

        .error {
            height: 26px;
        }
    </style>

</head>
<body>
    <form id="form1" runat="server">
        Name <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
        <br />
        <br />
        <asp:Button ID="btnSubmit" runat="server" Text="Submit" CssClass="error" onclick="btnSubmit_Click" />
    </form>
</body>
</html>


上面的
下载jquery 1.4.1 js和min.js并放入脚本文件夹里面项目



当我运行屏幕并点击提交按钮消息


for the above i download the jquery 1.4.1 js and min.js and put into the script folder inside the project

when i run the screen and click the submit button the message

Name should not be empty is not displaying.

please help me what is the mistake in my above code.

What I have tried:

Tried the below code but it is not working

推荐答案

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


#form1)。validate({

规则:{
<%= txtName.ClientID%>:{
required: true
},
},
消息:{
<%= txtName.ClientID% >:{
required: 名称不应为空
},
}

});
});
< / script >

< 样式 类型 = text / css >
label .错误 {
颜色 红色;
display 内联;
}

错误 {
height 26px;
}
< / 风格 >

< ; / head >
< body >
< 表格 id = form1 runat = server >
名称< asp:TextBox ID = txtName runat = 服务器 > < / asp:TextBox >
< br / >
< br / >
< asp:按钮 ID = btnSubmit runat = server 文字 = 提交 CssClass = 错误 onclick = btnSubmit_Click / >
< / form >
< / body >
< / html >
("#form1").validate({ rules: { "<%=txtName.ClientID %>": { required: true }, }, messages: { "<%=txtName.ClientID %>": { required: "Name should not be empty" }, } }); }); </script> <style type="text/css"> label.error { color: red; display: inline; } .error { height: 26px; } </style> </head> <body> <form id="form1" runat="server"> Name <asp:TextBox ID="txtName" runat="server"></asp:TextBox> <br /> <br /> <asp:Button ID="btnSubmit" runat="server" Text="Submit" CssClass="error" onclick="btnSubmit_Click" /> </form> </body> </html>


上面的
下载jquery 1.4.1 js和min.js并放入脚本文件夹里面项目



当我运行屏幕并点击提交按钮消息


for the above i download the jquery 1.4.1 js and min.js and put into the script folder inside the project

when i run the screen and click the submit button the message

Name should not be empty is not displaying.

please help me what is the mistake in my above code.

What I have tried:

Tried the below code but it is not working


jQuery Validation Plugin |使用jQuery进行表单验证 [ ^ ]

As在它的名字:它是一个插件,而不是jQuery的组成部分......

你也必须包含jQuery Validator JavaScriot文件......
jQuery Validation Plugin | Form validation with jQuery[^]
As in its name: it is a plugin and not integral part of jQuery...
You have to include jQuery Validator JavaScriot file too...


这篇关于使用jquery在文本框中进行验证不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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