<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'addManager.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<script type="text/javascript">
function username()
{
if((window.document.form.username.value.length==0)
{
alert("用户名不能为空");
form.username.focus();
return (false);
}
}</script>
<body>
<s:form name="form" action="Login" method="post">
用户名:<input type="text" name="username" maxlength="10" onBlur="return username()"/><br/>
密 码:<input type="password" name="password" maxlength="10"/><br/>
<s:submit value="提交"><br></s:submit>
</s:form>
</body>
</html>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'addManager.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<script type="text/javascript">
function username()
{
if((window.document.form.username.value.length==0)
{
alert("用户名不能为空");
form.username.focus();
return (false);
}
}</script>
<body>
<s:form name="form" action="Login" method="post">
用户名:<input type="text" name="username" maxlength="10" onBlur="return username()"/><br/>
密 码:<input type="password" name="password" maxlength="10"/><br/>
<s:submit value="提交"><br></s:submit>
</s:form>
</body>
</html>
{
alert("用户名不能为空");
form.username.focus();
return false;
}
{
if((document.getElementById("username").value.length==0)
{
alert("用户名不能为空");
document.getElementById("username").focus();
return (false);
}
}</script>
<body>
<s:form name="form" action="Login" method="post">
用户名:<input type="text" id="username" maxlength="10" onBlur="return usernamexxxx()"/><br/>
改为
function checkUserName(){
试试
按照我的想法 当用户名输入为空并失去焦点时 应该弹出用户名不能为空的提示框
可是焦点到了密码上也没有出现效果
用IE的话左下角会出现网页上有错误的提示 FF干脆就什么都没有了
function username1()
{
if(document.form.username.value.length==0)
{
alert("用户名不能为空");
document.form.username.focus();
}
}你的函数名称不能和表单元素重名啊。就是说你的函数叫username()而你的文本框也叫username 所有报错