我的ASP文本框的验证无法使用javascript和ASP.NET [英] Validation for my ASP textboxes is not working using javascript and ASP.NET
本文介绍了我的ASP文本框的验证无法使用javascript和ASP.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨!我只是想问为什么我的asp文本框的表单验证不起作用。应该就像用户没有在文本框中输入文本一样,段落标签中的描述将显示为请输入文本。但它没有用。请帮我解决这个问题。
我尝试过的事情:
以下是javascript的代码:
Hi! I just want to ask why my form validation for my asp textboxes is not working. It should be like when the user does not input a text in the textbox, a description in the paragraph tag will display to please input a text. But it is not working.Please help me on solving this.
What I have tried:
Here is the code for javascript:
function checkForm() {
var errors = [];
if ($("#itemBrand").value == "") {
errors[0] = "Please input a text!";
}
if ($("#itemModel").value == "") {
errors[1] = "Please input a text!";
}
if (errors.length > 0) {
if (errors[0] != null) {
document.getElementById("itemBrandValidate").innerHTML = errors[0];
}
if (errors[1] != null) {
document.getElementById("itemModelValidate").innerHTML = errors[1];
}
return false;
}
return true;
}
这是aspx:
And here is the aspx:
<asp:TextBox ID="itemBrand" runat="server" BackColor="#FFFF66" BorderColor="Black" BorderWidth="1px" Height="20px" Width="300px"></asp:TextBox><br />
<p id="itemBrandValidate"></p>
<asp:TextBox ID="itemModel" runat="server" BackColor="#FFFF66" BorderColor="Black" BorderWidth="1px" Height="20px" Width="300px"></asp:TextBox><br />
<p id="itemModelValidate"></p>
<asp:Button ID="Button1" runat="server" CssClass="submitButton" Text="Save Item" OnClick="Button1_Click" OnClientClick="return checkForm()"/>
推荐答案
( #itemBrand)。value == ){
errors [ 0 ] = 请输入文字!;
}
if (
("#itemBrand").value == "") { errors[0] = "Please input a text!"; } if (
( #itemModel)。value == ){
errors [ 1 ] = 请输入文字!;
}
if (errors.length> 0 ) {
if (errors [ 0 ]!= null ){
document .getElementById( itemBrandValidate)。innerHTML = errors [ 0 ];
}
如果(错误[ 1 ]!= < span class =code-keyword> null ){
document .getElementById( itemModelValidate)。innerHTML = errors [ 1 ];
}
返回 false ;
}
返回 true ;
}
("#itemModel").value == "") { errors[1] = "Please input a text!"; } if (errors.length > 0) { if (errors[0] != null) { document.getElementById("itemBrandValidate").innerHTML = errors[0]; } if (errors[1] != null) { document.getElementById("itemModelValidate").innerHTML = errors[1]; } return false; } return true; }
这是aspx:
And here is the aspx:
<asp:TextBox ID="itemBrand" runat="server" BackColor="#FFFF66" BorderColor="Black" BorderWidth="1px" Height="20px" Width="300px"></asp:TextBox><br />
<p id="itemBrandValidate"></p>
<asp:TextBox ID="itemModel" runat="server" BackColor="#FFFF66" BorderColor="Black" BorderWidth="1px" Height="20px" Width="300px"></asp:TextBox><br />
<p id="itemModelValidate"></p>
<asp:Button ID="Button1" runat="server" CssClass="submitButton" Text="Save Item" OnClick="Button1_Click" OnClientClick="return checkForm()"/>
使用。val() [ ^ 一>]而不是.value
use .val()[^] instead of.value
这篇关于我的ASP文本框的验证无法使用javascript和ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文