<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<script language="javascript">
<!--
function isfull(){
if (document.dd.username.value==""){
alert("用户名不能为空");
document.dd.username.focus();
return false;
}
if (document.dd.password.value==""){
alert("密码不能为空");
document.dd.password.focus();
return false;
}
return true;}
</script>
<body>
<form name="dd" method="post" action="" onSubmit="return isfull();">
<input type="text" name="username">
<input type="text" name="password">
<input type="submit" name="Submit" value="提交">
</form>
</body>
</html>
javascript验证输入框不能为空
最新推荐文章于 2022-11-04 13:59:57 发布
这是一个使用JavaScript进行基本表单验证的示例。代码检查用户名和密码字段是否为空,如果为空则显示警告并聚焦到相应字段。这对于确保用户输入有效信息至关重要。
979

被折叠的 条评论
为什么被折叠?



