我在asp.net中加入简单的代码后点击onClick停止响应,当oclient点击返回true时请任何人建议......
function loginEmpty() {
debugger
var flag = true;
var name = document.getElementById("username").value;
var pass = document.getElementById("userpassword").value;
if (name =='' || pass =='') {
document.getElementById('username').style.border = "solid 1px red";
document.getElementById('userpassword').style.border = "solid 1px red";
document.getElementById('loginMsg').style.display = "none";
document.getElementById('errorMsg').style.display = "block";
document.getElementById('errorMsg').innerHTML = "Required field can not leave blank.";
flag= false;
}
else {
flag = true;
document.getElementById('username').style.border = "solid 1px green";
document.getElementById('userpassword').style.border = "solid 1px green";
document.getElementById('errorMsg').innerHTML = " . ";
}
return flag;
}
答案 0 :(得分:0)
例如,下面是您的按钮:
在调用JavaScript方法之前添加return
,如下面示例所示:
<asp:Button runat="server" Text="My Button" ID="myButton" OnClientClick="return loginEmpty();" OnClick="myButton_OnClick" />