62,268
社区成员
发帖
与我相关
我的任务
分享
OnClientClick="checkForm();" 有问题,
应该
OnClientClick="return checkForm();" 这样才能return false
<asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
<asp:Button ID="btnSubmit" OnClientClick="checkForm();" runat="server" Text="提交" OnClick="btnSubmit_Click" />
<script type="text/javascript">
function checkForm() {
if (document.getElementById("<%=txtUserName.ClientID %>").value=="")
alert("用户名为空 ");
return false;
}
</script>
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (!comAPI.ExistString(txtUserName))//判断非空
{
Common.ShowMessages(this, "输入框不允许为空!");//Common是一个封装的类
return;
}
}
window.onload = function () {
var txtUserName= document.getElementById("<% =txtUserName.ClientID %>");
txtUserName.onfocus = function () {
//do something
}
txtLength.onblur = function () {
//如果不填写,验证不通过
return false;
}
}
<asp:Button CssClass="button" ID="btnSubmit" runat="server" Text="提交" OnClick="btnSubmit_Click" />
<div class="first">用户名:</div>
<div class="second">
<asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
</div>
document.getElementById("<%=控件ID.ClientID%>").value