<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>New Web Project</title>
<script>
var flag;
function checked(){
var username = document.getElementById("userId").value;
var pwd = document.getElementById("pwdid").value;
if (username == "") {
document.getElementById("userIds").innerHTML="用户名不能为空";
flag = false;
}
if (pwd == "") {
document.getElementById("pwdids").innerHTML="密码不能为空";
flag = false;
}
alert(flag);
return flag;
}
</script>
</head>
<body>
<form action="a.html" method="get" onsubmit="return checked()">
<input type="text" name="username" id="userId"/>
用户名 <input type="text" name="usernames" id="userIds"/>
<input type="text" name="pwd" id="pwdid"/>
密码 <input type="text" name="pwds" id="pwdids"/>
<input type="submit" value="提交"/>
</form>
</body>
</html>当我用户名 密码都为空的时候 为什么还能登录那
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>New Web Project</title>
<script>
var flag;
function checked(){
var username = document.getElementById("userId").value;
var pwd = document.getElementById("pwdid").value;
if (username == "") {
document.getElementById("userIds").innerHTML="用户名不能为空";
flag = false;
}
if (pwd == "") {
document.getElementById("pwdids").innerHTML="密码不能为空";
flag = false;
}
alert(flag);
return flag;
}
</script>
</head>
<body>
<form action="a.html" method="get" onsubmit="return checked()">
<input type="text" name="username" id="userId"/>
用户名 <input type="text" name="usernames" id="userIds"/>
<input type="text" name="pwd" id="pwdid"/>
密码 <input type="text" name="pwds" id="pwdids"/>
<input type="submit" value="提交"/>
</form>
</body>
</html>当我用户名 密码都为空的时候 为什么还能登录那
另外:document.getElementById("userIds").innerHTML="用户名不能为空";
text框是没有innerHTML的
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>New Web Project</title>
<script> var flag=true;
function checked(){
var username = document.getElementById("userId").value;
var pwd = document.getElementById("pwdid").value;
if (username == ""){
// document.getElementById("userIds").innerHTML="用户名不能为空";
alert("用户名不能为空");
flag = false;
}
if(pwd==""){
// document.getElementById("pwdids").innerHTML="密码不能为空";
alert("密码不能为空");
flag = false;
}
//alert(flag);
return flag;
}
</script>
</head>
<body>
<form action="a.html" method="get" onsubmit="return checked()">
<input type="text" name="username" id="userId"/>用户名
<input type="text" name="usernames" id="userIds"/>
<input type="text" name="pwd" id="pwdid"/>密码
<input type="text" name="pwds" id="pwdids"/>
<input type="submit" value="提交"/>
</form> </body>
</html>
function checked(){
var username = document.getElementById("userId").value;
var pwd = document.getElementById("pwdid").value;
if (username == "") {
document.getElementById("userIds").value="用户名不能为空";
flag = false;
}
if (pwd == "") {
document.getElementById("pwdids").value="密码不能为空";
flag = false;
}
alert(flag);
return flag;
}
input没有innerHTML,直接用value就行