我的二级连动

    技术2022-05-11  11

    小胖帮忙解决了用JS实现的连动,同时我用另外一种方法实现了 ,自此对脚本的数组和select有了新的认识

     

    <%@ page contentType="text/html; charset=GB18030" %><%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %><%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %><%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %><%@page import="checkNumber.CityBean" %><%@page import="java.util.ArrayList" %><html><head><title>selectTest</title></head><body bgcolor="#ffffff"><a href="select2Action.do">GO</a>

    <form method="post" action="selectTest.jsp"><br><br>select1<select name="select1" οnchange="select2Show(this)">  <option value="0" selected="selected">--select--</option>  <option value="1">湖北</option>  <option value="2">河南</option></select>

    <br>select2<select name="select2">  <option value="0" selected="selected">--select--</option>

    </select>

    <input type="submit" name="Submit" value="Submit"><input type="reset" value="Reset"></form></body></html>

    <script language="javascript">var qq=new Array();var  count=0;<%ArrayList list=null;CityBean bean=new CityBean();if(request.getAttribute("citylist")!=null){  list=(ArrayList)request.getAttribute("citylist");  for(int i=0;i<list.size();i++)  {    bean=(CityBean)list.get(i);%> qq[count]=new Array("<%=bean.getProvinceId()%>","<%=bean.getId()%>","<%=bean.getCityName()%>"); count++; // 方法三:// qq.push(CreateNewOperion("<%=bean.getProvinceId()%>","<%=bean.getId()%>","<%=bean.getCityName()%>"));<%  }}%>

    function select2Show(s){  ClearAll(document.all.select2);  for(var j=0;j<count;j++)  {    if(s.value==qq[j][0])    {      var op=new Option();//      //方法二//      document.all.select2.options[j]=new Option(qq[j][2], qq[j][1]);      //      方法一      op.value=qq[j][1];      op.text=qq[j][2];      document.all.select2.add(op,j);    }  }  //  方法三://  ClearAll(document.all.select2);//  for(var j=0;j<qq.length;j++)//  {////    if(s.value==qq[j].id){//      alert(qq[j].id);//      document.all.select2.add(qq[j]);}//  }}

    function CreateNewOperion(optionId,optionValue,optionText){  var newOption=new Option();  newOption.id=optionId;  newOption.value=optionValue;  newOption.text=optionText;  return newOption;}

    function ClearAll(selectobj){  for(var i=selectobj.options.length;i>0;i--)    selectobj.options.remove(0);}</script>


    最新回复(0)