一个页面多个表单,怎样根据情况只显示一个表单 假设一个book.jsp页面有两个表单:添加书籍、修改书籍。当在其他页面点‘添加’链接时,book.jsp只显示添加书籍的表单;当点修改链接时,book.jsp只显示修改书籍的表单。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个很好解决啊。接受一个值 类型值 在前台 用div 圈 form。用div 把所有div 默认为隐藏状态当用到form1 时 把div1显示用到form2时 把div2显示在前台 或者后台接受 那个参数 加以判断 用按钮做吧。当点击添加时,添加表单的visible为ture.当点击修改时反之 楼上说的很正确啊,用两个div控制,然后有js控制div的显示就行了 这个需要JavaScript控制,可是传递的参数不能放到jS脚本里啊,能给出大概的代码吗? 我觉得应该是在每一个<form>..... </form>代码中都加上<input type="submit" name="Submit" value="按钮">你先试一下对不对 在JS里直接通过ID获得然后控制visible就行了 <head> <title>注册&登录&修改用户</title> <script type="text/javascript"> function selectForm{ ...... } </script> </head> <body> <!--注册--> <div id="reg"> <html:form action="/reg" method="post" > ...... </html:form> </div> <!--登录--> <div id="login"> <html:form action="/login method="post" > ...... </html:form> </div> <!--修改个人信息--> <div id="modify"> <html:form action="/modify method="post" > ...... </html:form> </div></body>js怎么写? book.jsp页面有两个表单:添加书籍、修改书籍写两个页面不就行了么 我这有个测试登陆的用到了div隐藏,效果是点击测试按钮本页面弹出隐藏的iframe,不知道要不要,我感觉思路是一样的。就是点击的时候是原来隐藏的区域变成显示 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%><html><head><link href="css/pop.css" rel="stylesheet" type="text/css"> <script type="text/javascript"> //显示的方法,说明:前缀的div1、div2、body等,均为Id值 function show() { cover.style.display="inline";//设置层1显示 cover.style.width=body.clientWidth;//设置层1宽度等于body宽度,width=100%也可以,不过有一些误差,所以最好用这个 cover.style.height=body.clientHeight;//设置层1高度满屏 pop.style.display="inline";//设置层2的显示 pop.style.top=body.clientHeight/2-pop.clientHeight/2;//设置层2的距顶位置居中算法 pop.style.left=body.clientWidth/2-pop.clientWidth/2;//设置层2的距左位置居中算法 } //关闭显示 function closeShow() { cover.style.display="none"; pop.style.display="none"; } </script></head><body id="body"> <!--测试按钮点击触发show()方法--> <input type="button" value="测试按钮" onClick="show()"/><br> <c:if test="${!empty sessionScope.user}"> 当前用户:${sessionScope.user.username } </c:if> <a href="http://www.baidu.com">test</a> <div id="cover" class="cover"></div><!--这是要覆盖网页的层,不必写任何东西--> <div id="pop" class="pop"><!--这是弹出的模式窗口层--> <!--嵌套在层中的层,用来做标题栏,按个人需求定义--> <div id="div3" style="width:340px;height:20px; background-color:#E1F4DC;" align="right"> <label onClick="closeShow()" style="font-weight:bolder;cursor:hand"> 关闭 <!--用来关闭显示,在label中加了onclick事件,与鼠标悬停手的样式--> </label> </div> <iframe id="iframe" src="login.jsp" height="210px;""> </iframe> </div> </body> </html>引用的css是[code=CSS]@CHARSET "UTF-8";/*class 属性是.xxx开始标记id属性是#xxx开始标记*/.cover{ background-color: #C0C0C0; position: absolute; top: 0; left: 0; z-index: 1; display: none; filter:Alpha(opacity=30); }.pop{ text-align:center; width: 350px; height: 250px; background-color: #E1F4DC; position: absolute; z-index: 2; display: none; border: 0px inset #E1F4DC;}.div1{ /*本层要实现覆盖模式窗口以外全部内容的半透明效果*/ background-color:blue;/*背景色*/ position: absolute ;/*绝对定位,必选,使层绝对依照top,left的标准显示,否则将不能实现覆盖*/ top:0;/*层与页面顶部距离*/ left:0;/*层与左侧边距离*/ z-index:1;/*当发生重叠时的优先级,数大的会覆盖数较小的,没进行设置的均可视为小于0*/ display:none; /*层是否可见,初始化none不可见*/ filter:Alpha(opacity=30);/*过滤颜色,设置透明度(可见度)30,数越小越透明*/ } /*层2的样式*/ .div2{ /*本层显示在最前端,其它控件均不可用*/ width:300px;/*显示宽度*/ height:200px;/*显示高度*/ position:absolute;/*绝对定位*/ z-index:2;/*优先级*/ display: none;/*是否显示*/ border:0px inset blue; /*边框:宽度,样式,颜色*/ background-color:blue;/*背景色*/ }[/code] 思路不一样:你的这个我知道我要的是在a.jsp页面点不同的链接,跳转到b.jsp页面,b.jsp页面灵活地只显示多个表单中的一个表单。不同的链接对应不同的表单,链接与表单不是在同一个jsp页面。 你再jsp里面有标签做。在后台给前台一个参数 这个参数用标签就能得到 比如el表达式在标签里你用选择 具体的我忘了。这样可以实现的。 ....这个还不简单吗 你给没个连接加个参数 type = add or update 到book.jsp页面用String type =request.getParameter("type") if(type.equal("add")){里边写添加表单}else(里边是update 表单)这应该是你的意思吧 点击修改或者添加后,url地址例如,是这样 http://localhost:8080/book.jsp?flag=add function selectForm(){ var url=window.location.href; var flag=url.split("=")[1].split("&")[0]; alert(flag); //弹出add if("add"==flag){ ...... }else{ ..... } //具体实现,上面差不多给了你思路呢~~就是div的显示和隐藏~ } <c:choose> <c:when test="${param.action_name == 'add'}" > <form name="addBookForm" action="bookstore.add.do" method="post"> .... </form> </c:when> <c:when test="${param.action_name == 'modify'}"> <form name="modifyBookForm" action="bookstore.modify.do" method="post"> .... </form> </c:when></c:choose> 做出来了,就用JSTL就行了,不过有几点要注意: 1.如果后台request.setAttribute("type",type);前台就用<c:if test="${type=='loadUser'}"> 2.如果是链接<a href="User.jsp?type=addUser">添加用户</a>,就用 <c:if test="${param.type=='addUser'}"> 除非是关键字null,否则单引号必不可少。不管有多少表单,全部用<c:if>包起来就行了。如果每个jsp内容很简单的话,集合在一起,就减少了jsp的个数。谢谢各位。 谢谢,请问在.net里面我想实现这个应该咋办? 如何获取json数据的未知key的名称 层的显示和隐藏写法 tomcat如何初始化自定义类 关于jar包 菜鳥Hibernate問題 weblogic9 不支持EL? 如何在java中调用存储过程(含数组入,出参)? 请教写入文件中文出现乱码问题 spring+hibernate 无法关闭数据库连接 帮忙顶帖 人人有分 我是新来的,正准备学习J2EE,以后有问题要多请教大家了. jstl在jsp中的应用 在MyEclipse+tomcat下的项目中,导入xml内容时的错误
接受一个值 类型值
在前台 用div 圈 form。
用div 把所有div 默认为隐藏状态
当用到form1 时 把div1显示
用到form2时 把div2显示
在前台 或者后台接受 那个参数 加以判断
代码中都加上
<input type="submit" name="Submit" value="按钮">
你先试一下对不对
<title>注册&登录&修改用户</title>
<script type="text/javascript">
function selectForm{
......
}
</script>
</head>
<body>
<!--注册-->
<div id="reg">
<html:form action="/reg" method="post" >
......
</html:form>
</div> <!--登录-->
<div id="login">
<html:form action="/login method="post" >
......
</html:form>
</div> <!--修改个人信息-->
<div id="modify">
<html:form action="/modify method="post" >
......
</html:form>
</div>
</body>
js怎么写?
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<link href="css/pop.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
//显示的方法,说明:前缀的div1、div2、body等,均为Id值
function show()
{
cover.style.display="inline";//设置层1显示
cover.style.width=body.clientWidth;//设置层1宽度等于body宽度,width=100%也可以,不过有一些误差,所以最好用这个
cover.style.height=body.clientHeight;//设置层1高度满屏
pop.style.display="inline";//设置层2的显示
pop.style.top=body.clientHeight/2-pop.clientHeight/2;//设置层2的距顶位置居中算法
pop.style.left=body.clientWidth/2-pop.clientWidth/2;//设置层2的距左位置居中算法
}
//关闭显示
function closeShow()
{
cover.style.display="none";
pop.style.display="none";
}
</script>
</head>
<body id="body">
<!--测试按钮点击触发show()方法-->
<input type="button" value="测试按钮" onClick="show()"/><br>
<c:if test="${!empty sessionScope.user}">
当前用户:${sessionScope.user.username }
</c:if>
<a href="http://www.baidu.com">test</a> <div id="cover" class="cover"></div><!--这是要覆盖网页的层,不必写任何东西--> <div id="pop" class="pop"><!--这是弹出的模式窗口层-->
<!--嵌套在层中的层,用来做标题栏,按个人需求定义-->
<div id="div3" style="width:340px;height:20px; background-color:#E1F4DC;" align="right">
<label onClick="closeShow()" style="font-weight:bolder;cursor:hand">
关闭 <!--用来关闭显示,在label中加了onclick事件,与鼠标悬停手的样式-->
</label>
</div>
<iframe id="iframe" src="login.jsp" height="210px;"">
</iframe>
</div>
</body>
</html>
引用的css是[code=CSS]@CHARSET "UTF-8";/*class 属性是.xxx开始标记
id属性是#xxx开始标记*/.cover{
background-color: #C0C0C0;
position: absolute;
top: 0;
left: 0;
z-index: 1;
display: none;
filter:Alpha(opacity=30);
}
.pop{
text-align:center;
width: 350px;
height: 250px;
background-color: #E1F4DC;
position: absolute;
z-index: 2;
display: none;
border: 0px inset #E1F4DC;
}
.div1{
/*本层要实现覆盖模式窗口以外全部内容的半透明效果*/
background-color:blue;/*背景色*/
position: absolute ;/*绝对定位,必选,使层绝对依照top,left的标准显示,否则将不能实现覆盖*/
top:0;/*层与页面顶部距离*/
left:0;/*层与左侧边距离*/
z-index:1;/*当发生重叠时的优先级,数大的会覆盖数较小的,没进行设置的均可视为小于0*/
display:none; /*层是否可见,初始化none不可见*/
filter:Alpha(opacity=30);/*过滤颜色,设置透明度(可见度)30,数越小越透明*/
}
/*层2的样式*/
.div2{
/*本层显示在最前端,其它控件均不可用*/
width:300px;/*显示宽度*/
height:200px;/*显示高度*/
position:absolute;/*绝对定位*/
z-index:2;/*优先级*/
display: none;/*是否显示*/
border:0px inset blue; /*边框:宽度,样式,颜色*/
background-color:blue;/*背景色*/
}
[/code]
我要的是在a.jsp页面点不同的链接,跳转到b.jsp页面,b.jsp页面灵活地只显示多个表单中的一个表单。
不同的链接对应不同的表单,链接与表单不是在同一个jsp页面。
在后台给前台一个参数 这个参数用标签就能得到 比如el表达式
在标签里你用选择 具体的我忘了。
这样可以实现的。
String type =request.getParameter("type") if(type.equal("add")){里边写添加表单}else(
里边是update 表单
)
这应该是你的意思吧
var url=window.location.href;
var flag=url.split("=")[1].split("&")[0];
alert(flag); //弹出add
if("add"==flag){
......
}else{
.....
}
//具体实现,上面差不多给了你思路呢~~就是div的显示和隐藏~
}
<c:when test="${param.action_name == 'add'}" >
<form name="addBookForm" action="bookstore.add.do" method="post">
....
</form>
</c:when>
<c:when test="${param.action_name == 'modify'}">
<form name="modifyBookForm" action="bookstore.modify.do" method="post">
....
</form>
</c:when>
</c:choose>
1.如果后台request.setAttribute("type",type);前台就用<c:if test="${type=='loadUser'}">
2.如果是链接<a href="User.jsp?type=addUser">添加用户</a>,就用
<c:if test="${param.type=='addUser'}">
除非是关键字null,否则单引号必不可少。
不管有多少表单,全部用<c:if>包起来就行了。如果每个jsp内容很简单的话,集合在一起,就减少了jsp的个数。谢谢各位。