【发布时间】:2013-10-11 07:10:39
【问题描述】:
我正在使用 asp.net。我有一个登录表单。我已经在 Page 中为此编写了 Javascript 验证函数。
<table>
<tr>
<td>Username:></td>
<td><asp:TextBox runat="server" id="txtUsername"/></td>
<td>Password:></td>
<td><asp:TextBox runat="server" id="txtPassword"/></td>
<td>Username:></td>
<td><asp:Button runat="server" id="btnLogin" Text="Login" onclientclick="return Validatecp()"/></td>
</tr>
</table>
当我专注于文本框并按回车键时,整个页面正在重新加载。我想在按下输入按钮时显示验证。这可能吗?
编辑:
验证函数:
function Validatecp() {
var name = document.getElementById('<%=txtName.ClientID %>').value;
var password= document.getElementById('<%=txtTo.ClientID %>').value;
if (name == "") {
document.getElementById("td1").innerHTML = "Name Required.";
return false;
}
else {
document.getElementById("td1").innerHTML = "";
}
if (password== "") {
document.getElementById("td2").innerHTML = "password Required.";
return false;
}
else {
document.getElementById("td2").innerHTML = "";
}
return true;
}
【问题讨论】:
-
您需要出示您的验证码
-
如果您使用的是 Visual Studio,您可以简单地将验证控件添加到您的表单中。
标签: javascript jquery asp.net