select二级连动

xiaoxiao2022-06-13  55

下拉列表 <%@ page contentType="text/html;charset=GBK" %> <%@ taglib uri="/tags/web-flex" prefix="flex"%> <%@ taglib uri="/tags/web-grid" prefix="grid"%> <%@ taglib uri="/tags/web-html" prefix="html"%> <%@ taglib uri="/tags/web-loushang" prefix="loushang"%> <%@ taglib uri="/tags/loushang-bsp" prefix="bsp"%> <%@ page import="org.loushang.waf.ResourcesFactory"%> <%@ page import="java.util.ArrayList" %> <%@ page import="java.util.HashMap" %> <%@ page import="java.util.Iterator" %> <%@ page import="java.util.List"%> <%@ page import="java.util.Map"%> <%@ page import="org.loushang.util.RowSelection"%> <%@ page import="com.wonders.jzgc.common.cms_document.view.*" %> <%@ page import="com.wonders.jzgc.common.cms_document.service.*" %> <%@ page import="com.wonders.jzgc.common.cms_document.service.support.*" %> <%@ page import="com.wonders.jzgc.common.cms_site.view.*" %> <%@ page import="com.wonders.jzgc.common.cms_site.service.*" %> <%@ page import="com.wonders.jzgc.common.cms_site.service.support.*" %> <%@ page import="com.wonders.jzgc.common.cms_channel.view.*" %> <%@ page import="com.wonders.jzgc.common.cms_channel.service.*" %> <%@ page import="com.wonders.jzgc.common.cms_channel.service.support.*" %> <%@ page import="org.loushang.util.Page"%> <%@ page import="org.loushang.waf.ComponentFactory"%> <HTML> <HEAD> <TITLE>CMS_DOCUMENT查询</TITLE> <link rel="stylesheet" type="text/css" href="<loushang:ui css='skin.css'/>"> <script language="javascript" src="<loushang:ui js='flexgrid.js'/>"></script> <link rel="stylesheet" type="text/css" href="<loushang:ui css='flexgrid.css'/>"> </HEAD> <BODY topmargin="10px"> <% String sitId = request.getParameter("sitIdSearch"); String channelid=request.getParameter("channelidSearch"); String title=request.getParameter("titleSearch"); String curPages=request.getParameter("curPage"); int curPage=1; int rows=40; int firstRow=0; int totalPage=0; int totalRow=0; if(curPages!=null){ curPage=Integer.parseInt(curPages); } Map map=new HashMap(); //查询条件对像 if(sitId!=null&&!sitId.equals("")) { String[] sa0=new String[2]; sa0[0]=sitId; map.put("sitIdSearch",sa0); }else{ sitId="";} //sitId=""为不让翻面出面null if(channelid!=null&&!channelid.equals("")) { String[] sa1=new String[2]; sa1[0]=channelid; map.put("channelidSearch",sa1); }else{ channelid="";} // 为不让翻面出面null if(title!=null&&!title.equals("")) { String[] sa2=new String[2]; sa2[0]=title; map.put("titleSearch",sa2); }else{ title="";} // 为不让翻面出面null List list=new ArrayList(); Map map1=new HashMap(); ICmsSiteService cmsSiteService=(ICmsSiteService)ComponentFactory.getBean("cmsSiteService"); list=cmsSiteService.getAllCmsSiteNoPage(map1); int[] siteIds=new int[list.size()]; //定义 一维数组 int n=0; %> <form name="form1" method="post" action=""> <table border="0" width="700" align="center"> <tr> <td>地区: <!-- --------------------------选择框(一)----------------------------- --> <select name="cms_sit" onChange="redirec(document.form1.cms_sit.options.selectedIndex)"> <option selected>-请选择-</option> <% for(Iterator it=list.iterator();it.hasNext();) { CmsSiteView sitView=(CmsSiteView)it.next(); siteIds[n]=sitView.getSiteid(); //给一维数组 赋值 n++; if((sitId =="") || (Integer.parseInt(sitId) != sitView.getSiteid()) ) //判断是否有默认值 { %> <option value="<%=sitView.getSiteid()%>"><%=sitView.getSitedesc()%></option> <% } else{ %> <option value="<%=sitView.getSiteid()%>" selected ><%=sitView.getSitedesc()%></option> <% } } %> </select>  <!-- --------------------------选择框(二)----------------------------- --> <select name="cms_channel"> <option >-请选择-</option> </select>  <!-- --------------------------选择框(结束)------------------------------ --> 标题:<input type="text" name="cms_title" value="<%=title%>">   <img src="/shzjtd/jsp/images/submit1.gif" border="0" οnclick="querySubmit()"> </td> </tr> </table> <br> <% list=null; RowSelection rowSelection=new RowSelection(); //分页参数对像 rowSelection.setMaxRows(rows); firstRow=(curPage-1)*rows; rowSelection.setFirstRow(firstRow); ICmsDocumentService cmsDocumentService=(ICmsDocumentService)ComponentFactory.getBean("cmsDocumentService"); Page p=cmsDocumentService.getAllCmsDocumentSitId(rowSelection,map); totalRow=p.getCount(); totalPage=p.getPageCount(); list=p.getDatas(); %> <table border="1" width="700" align="center"> <tr> <th width="100">序号</th> <th width="100">区号</th> <th width="100">作者</th> <th width="400">标题</th> </tr> <% for(Iterator it=list.iterator();it.hasNext();) { CmsDocumentView view=(CmsDocumentView)it.next(); %> <tr> <td><%=view.getDocid()%></td> <td><%=view.getChannelid() %></td> <td><%=view.getAuthor()%></td> <td> <a href="#" onClick="JavaScript:window.open('<%=view.getPubfilename()%>','明细','width=542,height=500,scrollbar=no');" > <%=view.getTitle()%><a> </td> </tr> <% } %> </table> <table border="0" width="700" align="center"> <tr> <td> <table align="right" border="0" cellspacing="0" cellpadding="0"> <tr> <td style="font-size: 12px; color: #000000;"> <a href="#" onClick="turnPage(1)">首页</a> <a href="#" onClick="turnPage(<%=curPage%>-1)">上一页</a> <a href="#" onClick="turnPage(<%=curPage%>+1)">下一页</a> <a href="#" onClick="turnPage(<%=totalPage%>)">末页</a>  共<font color="red"><b><%=totalRow%></b></font>条记录   第<font color="red"><b><%=curPage%></b></font>页   共<font color="red"><b><%=totalPage%></b></font>页  <select name="currentpage" onChange="turnPage(this.value)"> <% for(int i=1;i<=totalPage;i++){ %> <option value="<%=i%>" <%if(i==curPage) out.print("selected");%> ><%=i%></option> <%}%> </select> </td> </tr> </table> </td> </tr> </table> <p> </form> <script language="javascript"> function turnPage(page){ if(page<=1){ page=1; } if(page>=<%=totalPage%>){ page=<%=totalPage%> } window.open("cms_document_query.jsp?curPage="+page+"&sitIdSearch=<%=sitId%>&channelidSearch=<%=channelid%>&titleSearch=<%=title%>","_self"); } var select1_len = document.form1.cms_sit.options.length; //获取一级菜单长度 var select2 = new Array(select1_len); //生成一个一维数组 for (i=0; i<select1_len; i++) //把一级下拉列表,都设为数组 ,也就是设为二维数组 { select2[i] = new Array();} select2[0][0] = new Option("-请选择- ", ""); <% //----------------------------------------------------------把表中的数据赋到js中 ICmsChannelService cmsChannelService=(ICmsChannelService)ComponentFactory.getBean("cmsChannelService"); List listchannel=new ArrayList(); listchannel = cmsChannelService.getAllCmsChannelNoPage(map1); int m; for(int j=1;j<n+1;j++) //n是一维数组的长度, j是从1开始的 { m=1; %> select2[<%=j%>][0]= new Option("-请选择- ", ""); <% for(Iterator it=listchannel.iterator();it.hasNext();) { CmsChannelView ChannelView=(CmsChannelView)it.next(); if(ChannelView.getSiteid()==siteIds[j-1]) //判断 是否相等 { %> select2[<%=j%>][<%=m%>] = new Option("<%=ChannelView.getChannelname()%>", "<%=ChannelView.getChannelid()%>"); <% m++; } } } // ----------------------------------------------------------把表中的数据赋到 js 结束 if(!sitId.equals("")) //----------------如果参数有值,让第二个下拉列有默认值 { %> var c_n = document.form1.cms_sit.options.selectedIndex; var c_chan = document.form1.cms_channel; c_chan.options.length=select2[c_n].length; for (i=0;i<select2[c_n].length;i++) { c_chan.options[i]=new Option(select2[c_n][i].text,select2[c_n][i].value); <% if(!channelid.equals("")) { %> if(select2[c_n][i].value == <%=channelid%>) c_chan.options[i].selected=true; <% } %> } <%}%> //--------------------------如果参数有值,让第二个下拉列有默认值 结束 function redirec(x) //联动函数 { var temp = document.form1.cms_channel; temp.options.length=select2[x].length; for (i=0;i<select2[x].length;i++) { temp.options[i]=new Option(select2[x][i].text,select2[x][i].value); } temp.options[0].selected=true; } function querySubmit()//查询提交 { cms_sit = document.form1.cms_sit.value; cms_channel = document.form1.cms_channel.value; title=document.form1.cms_title.value; window.open("cms_document_query.jsp?curPage=1&sitIdSearch="+cms_sit+"&channelidSearch="+cms_channel+"&titleSearch="+title,"_self"); } </script>
转载请注明原文地址: https://www.6miu.com/read-4936257.html

最新回复(0)