您的位置:首页 > 编程语言 > ASP

asp.net js验证为空j时,不让button执行onclick事件

2014-08-13 13:51 363 查看
<script type ="text/javascript" language="javascript">
function checkInput() {
var strMsg = "";
var userName = document.getElementById("<%=txt_Uer.ClientID%>").value;
var password = document.getElementById("<%=txt_Password.ClientID%>").value;
var txt_key = document.getElementById("<%=txt_key.ClientID%>").value;
if (userName == "" || userName == null) {
strMsg = "用户名"
}
if (password == "" || password == null) {
strMsg += " 密码"
}
if (txt_key == "" || txt_key == null) {
strMsg += " 验证码"
}
if (strMsg != "") {
alert(strMsg + " 不能为空!");
return false;
}
}
</script>

<asp:Button ID="Button1" runat="server" Text="登录" onclick="Button1_Click" OnClientClick="return checkInput()" />
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: