分类
使用Javascript编写一小段代码
<script type="text/javascript">
function check(){
var o=document.form1;
if(o.username.value==""){
alert("用户名不能为空");return false;
}
else{
if(!(/^[w]+$/.test(o.username.value))){
alert("用户名只能为数字和字母");return false;
}
}
if(o.password.value==""){
alert("密码不能为空");return false;
}
return true;
}
</script>
<form action="#" onsubmit="return check()" name="form1">
用户名 :<input type="text" name="username">
<br/>
密码:<input type="password" name="password">
</form>