使用jquery验证文本框 [英] Validate the textbox using jquery
问题描述
我有一个文本框。
名称文本框
使用Jquery验证上面的文本框。
用于下载jquery 1.4.1并放入该项目脚本。
< html xmlns = http ://www.w3.org/1999/xhtml >
< head runat = server >
< / head < span class =code-关键字>>
< body >
< form id = form1 runat = 服务器 > ;
< div >
< script < span class =code-attribute> 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({
规则:{
<%= txtName.UniqueID%>:{
required:true
},
}
},
消息:{
<% = txtName.UniqueID %>:{
required:名称不能为空
},
}
});
});
< / script >
< style type = text / css >
label 。错误 {
颜色 : red;
display : inline;
}
。错误
{
height : 26px;
}
< / 样式 >
< br / >
名称< asp:TextBox ID = < span class =code-keyword> txtName runat = server >
< br / >
< br / >
< asp:按钮 ID = btnSubmit runat = server 文字 = 提交 CssClass = 错误
< span class =code-attribute> onclick = btnSubmit_Click / >
< / div >
< / form >
< / body >
< span class =code-keyword>< / html >
i有一个文本框使用jquery验证文本框。
当我运行时如下
名称文本框
不输入文本框并单击提交消息未显示。
上述代码中的错误是什么。
我尝试过:
使用jquery验证文本框
( #form1)。validate({
rules:{
<%= txtName.UniqueID%>:{
required:true
},
}
},
条消息:{
<% = txtName.UniqueID%>:{
必填:姓名不应为空
},
}
});
});
< / script >
< style type = text / css >
label 。错误 {
颜色 : red;
display : inline;
}
。错误
{
height : 26px;
}
< / 样式 >
< br / >
名称< asp:TextBox ID = < span class =code-keyword> txtName runat = server >
< br / >
< br / >
< asp:按钮 ID = btnSubmit runat = server 文字 = 提交 CssClass = 错误
< span class =code-attribute> onclick = btnSubmit_Click / >
< / div >
< / form >
< / body >
< span class =code-keyword>< / html >
i有一个文本框使用jquery验证文本框。
当我运行时如下
名称文本框
不输入文本框并单击提交消息未显示。
上述代码中的错误是什么。
我尝试过:
使用jquery验证文本框
试试这个
始终在Head标签内放置 Scripts
和样式
/>
< html xmlns = http://www.w3.org/1999/xhtml >
< head >
< script src = Scripts / jquery-1.4.1.min.js < span class =code-attribute> type = text / javascript > < / script >
< script src = Scripts / jquery.validate.js 类型 = text / javascript > < / script >
< script type = text / javascript >
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">
<div>
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript">
</Script>
<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" />
</div>
</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
解决方案 (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" />
</div>
</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
Always place theScripts
andStyles
inside Head tag,
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"> </script> <script src="Scripts/jquery.validate.js" type="text/javascript"></script> <script type="text/javascript">
这篇关于使用jquery验证文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!