注册 登录
编程论坛 J2EE论坛

jsp 动态表格 隔行换色

earthsurface 发布于 2009-10-23 09:08, 3327 次点击
在界面上提交行数n和列数m,边界宽度,是否显示间隔色(用radio选择框)的4项信息。在页面上显示n×m的表格,表格具有提交的边界宽度。若选择了“要显示间隔色”,表格的奇数行显示黄色,偶数行显示灰色;若选择了“不显示间隔色”,表格的每行均为灰色  

扩展任务是界面上显示2组radio选择框,1组为是否显示行间隔色,1组为是否显示列间隔色。

我现在只会写基础的 请各位师兄帮帮忙

这是我写的基础部分的  哪位大哥帮我改改 让她可以满足上面的条件

<title>无标题文档</title>
<form action="" method="post">
请输入要显示表格的行数和列数:
<br>
行数:
<input type="text" name="row" value="" />
<br>
列数:
<input type="text" name="col" value="" />
<br>
<input type="radio" value="">是
<input type="radio" value="">否
<br>
<input type="submit" value="提交" />
</form>
<table cellpadding="0" cellspacing="0" border="1" width="75%">
      <%
          String num1str = request.getParameter("row");
          String num2str = request.getParameter("col");
          if(num1str == "" || num1str == null || num1str.equals("") || num1str.equals(null))
              num1str = "1";
          if(num2str == "" || num2str == null || num2str.equals("") || num2str.equals(null))
              num2str = "1";
          int row = Integer.valueOf(num1str);
          int col = Integer.valueOf(num2str);
          for(int i = 0 ; i < row ; i ++){
              %>
              <tr align="left" height="20">
              <%
              for(int j = 0 ;j < col ; j ++){
              %>
                  <td>[<%=i+1%>] | [<%=j+1%>]</td>
                  <%
              }
              %>
              </tr>
              <%
          }
      %>
      </table>

</body>
</html>
8 回复
#2
lampeter1232009-10-23 13:43
这个用JavaScript做会好些
#3
earthsurface2009-10-23 18:09
我也知道耶  但是老师叫我必须用JSP 做...    没办法耶  所以求助咯...  大哥帮帮忙嘛   谢谢
#4
earthsurface2009-10-24 16:44
  其实是个很简单的问题    怎么就没人帮帮忙呢  谢谢各位了嘛  我知道用if(row%2==0){ }
  就是大括号里怎么用BGcolor不知道    跪求大家的帮忙啊
#5
柠檬可乐2009-10-25 00:37
<input type="radio" value="">是
<input type="radio" value="">否
这里改成
<input type="radio" value="shi">是  
<input type="radio" value="fou">否
程序代码:
<%
String num1str = request.getParameter("row");
String num2str = request.getParameter("col");
String str=request.getParameter("radio");
         
int row = Integer.valueOf(num1str);
int col = Integer.valueOf(num2str);

if(str.equals("shi")){
for(int i = 0 ; i < row ; i ++){
if(i%2==0){
out.print("<tr bgcoloor=#FFFF00>");//黄
for(int j = 0 ;j < col ; j ++){
out.print("<td>");
out.print("</td>");
out.print("</tr>");
}
}
else {
out.print("<tr bgcoloor=#CCCCCC>"); //灰
for(int j = 0 ;j < col ; j ++){
out.print("<td>");
out.print("</td>");
out.print("</tr>");
}}
}
}
 
else if(str.equals("fou")){
for(int i = 0 ; i < row ; i ++){
out.print("<tr bgcoloor=#CCCCCC>");//灰
for(int j = 0 ;j < col ; j ++){
out.print("<td>");
out.print("</td>");
out.print("</tr>");
}
}}
%>


你试一下这样行不行,我没有运行过,不知道可不可以




#6
lampeter1232009-10-26 12:38
以下是引用柠檬可乐在2009-10-25 00:37:17的发言:

<input type="radio" value="">是
<input type="radio" value="">否
这里改成
<input type="radio" value="shi">是  
<input type="radio" value="fou">否<%
String num1str = request.getParameter("row");
Stri ...
<input type="radio" value="shi" name="radio" checked>是
<input type="radio" value="fou" name="radio">否
一组单选按钮要有同一个name

[ 本帖最后由 lampeter123 于 2009-10-26 12:40 编辑 ]
#7
earthsurface2009-10-27 20:44
非常感谢 两位 师兄
#8
柠檬可乐2009-10-27 23:37
以下是引用earthsurface在2009-10-27 20:44:08的发言:

非常感谢 两位 师兄
那个呀,应该是师兄和师姐喔
#9
baifenghan2009-11-03 21:54
你们俩又教坏了一个孩子,建议把使用标签的该他也写出来看看,看看那段页面代码我就不舒服了
1