把内容过程重要的一些内容段做个记录,下边资料是关于asp.net 环境下当javascript验证不通过是禁止button按钮执行onclick事件的内容。
<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="登录" οnclick="Button1_Click" OnClientClick="return checkInput()" />
转载于:https://blog.51cto.com/14117740/2325847