在表单的table中的每一个单元格加入俩个下拉菜单,求大神指导怎么写,跪求~

在表单的table中的每一个单元格加入俩个下拉菜单,求大神指导怎么写?下面有初步的jsp代码。我用的是SSH框架.有一个下拉菜单的值是动态的,是别的表内的属性。怎么把一个单元格里的两个数据分别确定

图片说明

 <%@page contentType="text/html;  charset=UTF-8" import="java.util.*" %>
<%@ page import="com.sysgrrj.module.ChangFangGouMai.valueobject.ChangFangGouMai" %>
<%@ page import="com.sysgrrj.common.TypeChange" %>
<%@  taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
    <jsp:include page='/res/inc/inc.jsp' flush='true'/>
</head>
<body>
<s:form action="List" id="form1" theme="simple">
    <jsp:include page='/res/inc/inc_form_List.jsp' flush='true'/>
    <script type="text/javascript">
        function doAction(action) {
            if (confirm("是否确认保存?")) {

                document.getElementById("form1").action = "<%=request.getContextPath()%>/Module/ChangFangGouMai/List_save.action";
                document.getElementById("form1").submit();
                return true;
            }
            else {
                return false;
            }
        }




    </script>


    <div class="buttonDiv">


        <input type="button" class="button_style_save" onclick="doAction('')"/>
    </div>
    <div class="validatemsg">
        <s:actionerror/>
        <s:fielderror/>
        <s:actionmessage/>
    </div>

    <%


           //厂房购买
           List<ChangFangGouMai> changFangGouMaiList = (List<ChangFangGouMai>) request.getAttribute("changFangGouMaiList");


       %>





<table width="100%" class="listext" id="table1">
        <tr>
            <TH colspan="7" style="background:  #EBEBEB;height: 35px"> 厂房购买</TH>
        </tr>
    <TR>

       <TH width="30"> 序号</TH>
       <TH width="80">编号</TH>
       <TH>1</TH>
       <TH>2</TH>
       <TH>3</TH>
        <TH>4</TH>

       <%--<TH>trainingOrCompetitionID</TH>--%>
    </TR>

       <%   int i;
           int k;
           int j;
             String[] s;
              s=new String[6];
             for(j=1;j<7;j++){
                 String a[]={"第一年","第二年","第三年","第四年","第五年","第六年"};
        %>
      <TR>

          <TD><%=(j)%> </TD>
           <TD><%=(a[j-1])%> </TD>
          <%
             for(i=1;i<5;i++){
                 out.print("  <TD>");
                  String sr= "";
                 for(k=0;k<changFangGouMaiList.size();k++){
                     ChangFangGouMai changFangGouMai=changFangGouMaiList.get(k);
                     if(TypeChange.stringToInt(changFangGouMai.getNianDu())==j&&changFangGouMai.getBianHao()==i){
                         sr=changFangGouMai.getZuYongHuoGouMai();
                         break;
                     }
                 }
                 out.print("<input type=\"text\"   name=\""+j+"_"+i+"\" value=\"" + sr + "\"/>");
                 out.print("</TD>");

             }
          %>







       </TR>

      <%

          }

        %>
</TABLE>
    <s:hidden name="TrainingOrCompetitionID"/>
</s:form>
</body>
</html>

2个回答

只能用ajax了,用js动态生成select标签,使用ajax返回来的数据填充option

ascdfwsfrfadfg
inc1ud3 回复baidu_29643173: 可以去http://www.w3school.com.cn/jquery/index.asp
接近 5 年之前 回复
ascdfwsfrfadfg
inc1ud3 回复baidu_29643173: 引入jquery,然后发送ajax请求,后台返回那个下拉菜单的值,在ajax的success:{//这里动态添加select标签}
接近 5 年之前 回复
baidu_29643173
baidu_29643173 哥,我是新手,也听不懂啊?这个是已经差不多的代码了,你能直接在上面给我改下吗
接近 5 年之前 回复
 <%@page contentType="text/html;  charset=UTF-8" import="java.util.*" %>
<%@ page import="com.sysgrrj.module.ChangFangGouMai.valueobject.ChangFangGouMai" %>
<%@ page import="com.sysgrrj.common.TypeChange" %>
<%@  taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
    <jsp:include page='/res/inc/inc.jsp' flush='true'/>
</head>
<body>
<s:form action="List" id="form1" theme="simple">
    <jsp:include page='/res/inc/inc_form_List.jsp' flush='true'/>
    <script type="text/javascript">
        function doAction(action) {
            if (confirm("是否确认保存?")) {

                document.getElementById("form1").action = "<%=request.getContextPath()%>/Module/ChangFangGouMai/List_save.action";
                document.getElementById("form1").submit();
                return true;
            }
            else {
                return false;
            }
        }




    </script>


    <div class="buttonDiv">


        <input type="button" class="button_style_save" onclick="doAction('')"/>
    </div>
    <div class="validatemsg">
        <s:actionerror/>
        <s:fielderror/>
        <s:actionmessage/>
    </div>

    <%


           //厂房购买
           List<ChangFangGouMai> changFangGouMaiList = (List<ChangFangGouMai>) request.getAttribute("changFangGouMaiList");


       %>





<table width="100%" class="listext" id="table1">
        <tr>
            <TH colspan="7" style="background:  #EBEBEB;height: 35px"> 厂房购买</TH>
        </tr>
    <TR>

       <TH width="30"> 序号</TH>
       <TH width="80">编号</TH>
       <TH>1</TH>
       <TH>2</TH>
       <TH>3</TH>
        <TH>4</TH>

       <%--<TH>trainingOrCompetitionID</TH>--%>
    </TR>

       <%   int i;
           int k;
           int j;
             String[] s;
              s=new String[6];
             for(j=1;j<7;j++){
                 String a[]={"第一年","第二年","第三年","第四年","第五年","第六年"};
        %>
      <TR>

          <TD><%=(j)%> </TD>
           <TD><%=(a[j-1])%> </TD>
          <%
             for(i=1;i<5;i++){
                 out.print("  <TD>");
                  String sr= "";
                 for(k=0;k<changFangGouMaiList.size();k++){
                     ChangFangGouMai changFangGouMai=changFangGouMaiList.get(k);
                     if(TypeChange.stringToInt(changFangGouMai.getNianDu())==j&&changFangGouMai.getBianHao()==i){
                         sr=changFangGouMai.getZuYongHuoGouMai();
                         break;
                     }
                 }
                 out.print("<input type=\"text\"   name=\""+j+"_"+i+"\" value=\"" + sr + "\"/>");
                 out.print("</TD>");

             }
          %>

          <!-- 新增部分  -->

          <td>
            <select>
              <option value="1" <c:if test="${user.type eq '1'}">checked="checked"</c:if>  >选项1</option>
              <option value="2" <c:if test="${user.type eq '2'}">checked="checked"</c:if>  >选项2</option>
            </select>
          </td>
           <!-- 新增部分END  -->
           <!--
           返回一个列表项,通过EL表达式判断值是否对应当前选项,然后进行设置即可.
           -->





       </TR>

      <%

          }

        %>
</TABLE>
    <s:hidden name="TrainingOrCompetitionID"/>
</s:form>
</body>
</html>
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问