改了一中午了,我的javascript 怎么就是不起作用呢?程序在下面,请好心人帮忙指点。
<%@pagecontentType="text/html;charset=gb2312"%><html><head><title>输入追加页面</title><scri...
<%@page contentType="text/html; charset=gb2312" %>
<html>
<head>
<title>输入追加页面 </title>
<script language="javascript">
function on_submit()
{
if(form1.username == "")
{
alert("请输入您的姓名!");
form1.username.focus();
return false;
}
if(form1.age == "")
{
alert("请输入您的年龄!");
form1.age.focus();
return false;
}
if(form1.dept == "")
{
alert("请输入您的系别!");
form1.dept.focus();
return false;
}
}
</script>
</head>
<body>
<table border="1" width="700">
<tr >
<td colspan="2" align="center">用户注册程序</td>
</tr>
<form action="" method="post" onsubmit="return on_submit()" name="form1">
<tr>
<td width="25%">用户名 :</td>
<td><input type="text" name="username">(*)必填</td>
</tr>
<tr>
<td width="25%">年龄</td>
<td><input type="text" name="age">(*)必填</td>
</tr>
<tr>
<td width="25%">性别</td>
<td>
<input type="radio" name="sex" value="男" checked>男
<input type="radio" name="sex" value="女">女</td>
</tr>
<tr>
<td width="25%">系别</td>
<td><input type="text" name="dept">(*)必填</td>
</tr>
<tr>
<td width="25%">ID :</td>
<td><input type="text" readonly="readonly" name="id" value="id"></td>
</tr>
<tr>
<td colspan="2" align="center"> <input type="submit" value="提交"><input type="reset" value="重输"></td>
</tr>
</form>
</table>
</body>
</html>
真的对了,非常感谢!但还有问题,为什么空白按提交按钮,提示:“请输入您的姓名”在姓名栏没有获得焦点,点击提示框的确定按钮,就直接跳转了??? 展开
<html>
<head>
<title>输入追加页面 </title>
<script language="javascript">
function on_submit()
{
if(form1.username == "")
{
alert("请输入您的姓名!");
form1.username.focus();
return false;
}
if(form1.age == "")
{
alert("请输入您的年龄!");
form1.age.focus();
return false;
}
if(form1.dept == "")
{
alert("请输入您的系别!");
form1.dept.focus();
return false;
}
}
</script>
</head>
<body>
<table border="1" width="700">
<tr >
<td colspan="2" align="center">用户注册程序</td>
</tr>
<form action="" method="post" onsubmit="return on_submit()" name="form1">
<tr>
<td width="25%">用户名 :</td>
<td><input type="text" name="username">(*)必填</td>
</tr>
<tr>
<td width="25%">年龄</td>
<td><input type="text" name="age">(*)必填</td>
</tr>
<tr>
<td width="25%">性别</td>
<td>
<input type="radio" name="sex" value="男" checked>男
<input type="radio" name="sex" value="女">女</td>
</tr>
<tr>
<td width="25%">系别</td>
<td><input type="text" name="dept">(*)必填</td>
</tr>
<tr>
<td width="25%">ID :</td>
<td><input type="text" readonly="readonly" name="id" value="id"></td>
</tr>
<tr>
<td colspan="2" align="center"> <input type="submit" value="提交"><input type="reset" value="重输"></td>
</tr>
</form>
</table>
</body>
</html>
真的对了,非常感谢!但还有问题,为什么空白按提交按钮,提示:“请输入您的姓名”在姓名栏没有获得焦点,点击提示框的确定按钮,就直接跳转了??? 展开
2个回答
展开全部
<html>
<head>
<title>输入追加页面 </title>
<script language="javascript">
function on_submit()
{
if(form1.username.value == "")
{
alert("请输入您的姓名!");
form1.username.focus();
return false;
}
if(form1.age.value == "")
{
alert("请输入您的年龄!");
form1.age.focus();
return false;
}
if(form1.dept.value == "")
{
alert("请输入您的系别!");
form1.dept.focus();
return false;
}
}
</script>
</head>
<body>
<table border="1" width="700">
<tr >
<td colspan="2" align="center">用户注册程序</td>
</tr>
<form action="" method="post" onsubmit="return on_submit()" name="form1">
<tr>
<td width="25%">用户名 :</td>
<td><input type="text" name="username">(*)必填</td>
</tr>
<tr>
<td width="25%">年龄</td>
<td><input type="text" name="age">(*)必填</td>
</tr>
<tr>
<td width="25%">性别</td>
<td>
<input type="radio" name="sex" value="男" checked>男
<input type="radio" name="sex" value="女">女</td>
</tr>
<tr>
<td width="25%">系别</td>
<td><input type="text" name="dept">(*)必填</td>
</tr>
<tr>
<td width="25%">ID :</td>
<td><input type="text" readonly="readonly" name="id" value="id"></td>
</tr>
<tr>
<td colspan="2" align="center"> <input type="submit" value="提交"><input type="reset" value="重输"></td>
</tr>
</form>
</table>
</body>
</html>
form1.username.value =="" 对
form1.username=="" 错
要给分阿
<head>
<title>输入追加页面 </title>
<script language="javascript">
function on_submit()
{
if(form1.username.value == "")
{
alert("请输入您的姓名!");
form1.username.focus();
return false;
}
if(form1.age.value == "")
{
alert("请输入您的年龄!");
form1.age.focus();
return false;
}
if(form1.dept.value == "")
{
alert("请输入您的系别!");
form1.dept.focus();
return false;
}
}
</script>
</head>
<body>
<table border="1" width="700">
<tr >
<td colspan="2" align="center">用户注册程序</td>
</tr>
<form action="" method="post" onsubmit="return on_submit()" name="form1">
<tr>
<td width="25%">用户名 :</td>
<td><input type="text" name="username">(*)必填</td>
</tr>
<tr>
<td width="25%">年龄</td>
<td><input type="text" name="age">(*)必填</td>
</tr>
<tr>
<td width="25%">性别</td>
<td>
<input type="radio" name="sex" value="男" checked>男
<input type="radio" name="sex" value="女">女</td>
</tr>
<tr>
<td width="25%">系别</td>
<td><input type="text" name="dept">(*)必填</td>
</tr>
<tr>
<td width="25%">ID :</td>
<td><input type="text" readonly="readonly" name="id" value="id"></td>
</tr>
<tr>
<td colspan="2" align="center"> <input type="submit" value="提交"><input type="reset" value="重输"></td>
</tr>
</form>
</table>
</body>
</html>
form1.username.value =="" 对
form1.username=="" 错
要给分阿
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询