1.简单的用户名和密码框,不输入值时,弹出提示框。
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>test</title>
<style></style>
</head>
<body>
<center>
<form name="form1" method="post" action="">
用户名:<input name ="user" type="text" id = "user"><br>
密码:<input name="pwd" type = "text" id = "pwd"><br>
<input name="Button" type="button" class="btn_grey" value="登录" onclick="check()">
<input name = "submit2" type="reset" class ="btn_grey" value="重置">
</form>
</center>
<script language="javascript">
function check(){
if(form1.user.value==""){
alert("请输入用户名!");
form1.user.focus();
return;
}else if (form1.pwd.value==""){
alert("请输入密码!");
form1.pwd.focus();
return;
}else{
form1.submit(); //提交表单
}
}
</script>
结果如下图