js检测用户名和密码不能为空

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>登录界面</title>
<script>
function inputNull(form)
{
	for(i=0;i<form.length;i++)
	{
		if(form.elements[i].value=="")	
		{
			alert("亲:"+form.elements[i].placeholder+"不能为空");
			form.elements[i].focus();	
			return false;
		}
	}	
}
</script>
</head>

<body>
<form action="testlogin.php" method="post" onSubmit="return inputNull(this)">
用户名:<input type="text" placeholder="用户名" name="userName">  
<br>
密 码:<input type="password" placeholder="密码" name="password">	
<br>
<input type="submit" value="登录">

</form>
<a id="btn_register" href="#"><input type="submit" value="注册"></a>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/qq_42058441/article/details/85211965