如下代码,要求当点击不同意按钮时不会弹出"不能为空!"直接跳到另一页面,
(可以获得的q参数与no参数的值)
要求当点击同意按钮时弹出"不能为空!"
<html>
<head> <title> ere </title> </head>
<body>
<form method="post" action="ok.jsp" onsubmit="return Checkok();">
<table>
<tr> <td>
<INPUT TYPE="text" NAME="q" value="333">
<INPUT TYPE="text" NAME="qw" value="">
</td> </tr>
<tr> <td>
<input type='submit' name='no' value=' 不同意 '>
<input type='submit' name='yes' value=' 同意 '>
</td> </tr>
<table>
</form>
</body>
</html>
<SCRIPT LANGUAGE="JavaScript">
function Checkok()
{
if(document.all("qw").value == "")
{
alert("不能为空!");
document.all("qw").focus();
return false;
}else
{ return true; }
}
</Script>
ok.jsp
<%
String qw=request.getParameter("qw");
String q=request.getParameter("q");
String no=request.getParameter("no");
String yes=request.getParameter("yes");
out.print(no);
out.print(yes);
%>
(可以获得的q参数与no参数的值)
要求当点击同意按钮时弹出"不能为空!"
<html>
<head> <title> ere </title> </head>
<body>
<form method="post" action="ok.jsp" onsubmit="return Checkok();">
<table>
<tr> <td>
<INPUT TYPE="text" NAME="q" value="333">
<INPUT TYPE="text" NAME="qw" value="">
</td> </tr>
<tr> <td>
<input type='submit' name='no' value=' 不同意 '>
<input type='submit' name='yes' value=' 同意 '>
</td> </tr>
<table>
</form>
</body>
</html>
<SCRIPT LANGUAGE="JavaScript">
function Checkok()
{
if(document.all("qw").value == "")
{
alert("不能为空!");
document.all("qw").focus();
return false;
}else
{ return true; }
}
</Script>
ok.jsp
<%
String qw=request.getParameter("qw");
String q=request.getParameter("q");
String no=request.getParameter("no");
String yes=request.getParameter("yes");
out.print(no);
out.print(yes);
%>
解决方案 »
- 有关在struts2中Action里面的Spring的“接口”还是“实例”注入问题
- 求几个图片验证码程序
- 请教:一个DIV(有横向和纵向滚动条)通过设置2个onscroll,分别控制另两个DIV(一个有横向滚动条,另一个有纵向滚动条)同时滚动,能否实现?
- 设置下载链接问题
- 对于数据库中存储密码不采取明码,大家有什么好的建议?
- 为什么用request.getParameter("xml")得不出textarea的值?急??????在线等
- 如何让第一个checkbox的值无法修改
- tomcat下mysql数据源的配置,SOS!
- 为什么我的jsp不能运行?
- 紧急问题,请问在JSP下能否打开Word文件
- hibernate持久化问题
- 急!!在线等有结果马上散分
应该是普通按钮,事件是onclick调用js,在js函数里面用 表单名+submit();提交表单就ok
<head> <title> ere </title> </head>
<body>
<form method="post" action="ok.jsp" onsubmit="return Checkok();">
<table>
<tr> <td>
<INPUT TYPE="text" NAME="q" value="333">
<INPUT TYPE="text" NAME="qw" value="">
</td> </tr>
<tr> <td>
<input name="no" type="button" onclick="http://不同意对应的网址"/>
<input type='submit' name='yes' value=' 同意 '>
</td> </tr>
<table>
</form>
</body>
</html>
<SCRIPT LANGUAGE="JavaScript">
function Checkok()
{
if(document.all("qw").value == "")
{
alert("不能为空!");
document.all("qw").focus();
return false;
}else
{ return true; }
}
</Script>
ok.jsp
<%
String qw=request.getParameter("qw");
String q=request.getParameter("q");
String no=request.getParameter("no");
String yes=request.getParameter("yes");
out.print(no);
out.print(yes);
%>
<head> <title> ere </title> </head>
<body>
<form method="post" action="ok.jsp" onsubmit="return Checkok();">
<table>
<tr> <td>
<INPUT TYPE="text" NAME="q" value="333">
<INPUT TYPE="text" NAME="qw" value="">
</td> </tr>
<tr> <td>
<input type='button' onclick="gotoOtherPage()" name='no' value=' 不同意 '>
<input type='submit' name='yes' value=' 同意 '>
</td> </tr>
<table>
</form>
</body>
</html>
<SCRIPT LANGUAGE="JavaScript">
function Checkok()
{
if(document.all("qw").value == "")
{
alert("不能为空!");
document.all("qw").focus();
return false;
}else
{ return true; }
}
function gotoOtherPage(){
... 写你的代码吧!
}
</Script>
注意上面的红色部分<input>的结束的"/"都忘记加了
<head>
<title>ere</title>
<SCRIPT LANGUAGE="JavaScript">
function Checkok(inputName) {
if(inputName=='no') return true;
if(inputName=='yes') {
if(document.all("qw").value == "") {
alert("不能为空!");
document.all("qw").focus();
return false;
} else {
return true;
}
}
}
</Script>
</head>
<body>
<form method="post" action="Ok.jsp">
<table>
<tr>
<td><INPUT TYPE="text" NAME="q" value="333"> <INPUT
TYPE="text" NAME="qw" value=""></td>
</tr>
<tr>
<td><input type='submit' name='no' value='Agree' onclick=Checkok('no')>
<input type='submit' name='yes' value='Disagree' onclick=Checkok('yes')>
</td>
</tr>
</table>
</form>
</body>
</html>