方法一:
代码语言:javascript复制<script type="text/javascript">
function check(form) {
if(form.userId.value=='') {
alert("请输入用户帐号!");
form.userId.focus();
return false;
}
if(form.password.value==''){
alert("请输入登录密码!");
form.password.focus();
return false;
}
return true;
}
</script>
<form action="login.do?act=login" method="post">
用户帐号
<input type=text name="userId" size="18" value="" >
<br>
登录密码
<input type="password" name="password" size="19" value=""/>
<input type=submit name="submit1" value="登陆" οnclick="return check(this.form)">
</form>
方法二:
代码语言:javascript复制<script type="text/javascript">
function check(form) {
if(form.userId.value=='') {
alert("请输入用户帐号!");
form.userId.focus();
return false;
}
if(form.password.value==''){
alert("请输入登录密码!");
form.password.focus();
return false;
}
return true;
}
</script>
<form action="login.do?act=login" method="post" οnsubmit="return check(this)">
用户帐号
<input type=text name="userId" size="18" value="" >
<br>
登录密码
<input type="password" name="password" size="19" value=""/>
<input type=submit name="submit1" value="登陆">
</form>
方法三:
代码语言:javascript复制<script type="text/javascript">
function check(form) {
if(form.userId.value=='') {
alert("请输入用户帐号!");
form.userId.focus();
return false;
}
if(form.password.value==''){
alert("请输入登录密码!");
form.password.focus();
return false;
}
document.myform.submit();
}
</script>
<form action="login.do?act=login" name="myform" method="post">
用户帐号
<input type=text name="userId" size="18" value="" >
<br>
登录密码
<input type="password" name="password" size="19" value=""/>
<input type=button name="submit1" value="登陆" οnclick="check(this.form)">
</form>