文本框的Jquery验证 [英] Jquery validation for textbox
问题描述
我有一个文本框。
名称文本框
使用Jquery验证上面的文本框。
用于下载jquery 1.4.1并放入该项目脚本。
< html xmlns =http://www.w3.org/1999/xhtml>
< head runat =server >
< / head>
< body>
< form id =form1runat =server>
i have one text box.
Name textbox
Validate the above textbox using Jquery.
for that download the jquery 1.4.1 and put in that project script.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
</head>
<body>
<form id="form1" runat="server">
< script src =Scripts / jquery-1.4.1.min.jstype =text / javascript>
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript">
<script src="Scripts/jquery.validate.js" type="text/javascript"></script>
<script type ="text/javascript" >
$(document).ready(function () {
$("#form1").validate({
rules: {
<%=txtName.UniqueID %>:{
required:true
},
}
},
messages: {
<%=txtName.UniqueID %>:{
required: "Name should not be empty"
},
}
});
});
</script>
<style type ="text/css" >
label.error {
color: red;
display:inline;
}
.error
{
height: 26px;
}
</style>
<br />
Name <asp:TextBox ID="txtName" runat="server">
<br />
<br />
<asp:Button ID="btnSubmit" runat="server" Text="Submit" CssClass="error"
onclick="btnSubmit_Click" />
< / form>
< / body>
< / html>
i有一个文本框使用jquery验证文本框。
当我运行如下
名称文本框
无需输入文本框并单击提交消息未显示。
上面代码中的错误是什么。
我尝试过:
使用JQuery验证文本框
</form>
</body>
</html>
i have one text box validate that textbox using jquery.
When i run as follows
Name textbox
Without typing in text box and click submit message not shown.
what is the mistake in my above code.
What I have tried:
validate the textbox using JQuery
推荐答案
(文档).ready(function( ){
(document).ready(function () {
(#form1)。validate({
规则:{
<%= txtName.UniqueID%>:{需要
:真
},
}
},
消息:{
<%= txtName.UniqueID%>:{
required:名称不能为空
},
}
});
});
< / script>
< style type =text / css>
label.error {
color:red;
显示:内联;
}
.error
{
身高:26px;
}
< / style>
< br />
名称< asp:TextBox ID =txtNamerunat =server>
< br />
< br />
< asp:Button ID =btnSubmitrunat =serverText =SubmitCssClass =error
onclick =btnSubmit_Click/>
("#form1").validate({ rules: { <%=txtName.UniqueID %>:{ required:true }, } }, messages: { <%=txtName.UniqueID %>:{ required: "Name should not be empty" }, } }); }); </script> <style type ="text/css" > label.error { color: red; display:inline; } .error { height: 26px; } </style> <br /> Name <asp:TextBox ID="txtName" runat="server"> <br /> <br /> <asp:Button ID="btnSubmit" runat="server" Text="Submit" CssClass="error" onclick="btnSubmit_Click" />
< / form>
< / body>
< / html>
i有一个文本框使用jquery验证文本框。
当我运行如下
名称文本框
无需输入文本框并单击提交消息未显示。
上面代码中的错误是什么。
我尝试过:
使用JQuery验证文本框
</form>
</body>
</html>
i have one text box validate that textbox using jquery.
When i run as follows
Name textbox
Without typing in text box and click submit message not shown.
what is the mistake in my above code.
What I have tried:
validate the textbox using JQuery
试试这个
Try This
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.js" type="text/javascript"> </script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.15.0/jquery.validate.js" type="text/javascript"></script>
<script type="text/javascript">
这篇关于文本框的Jquery验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!