js+jsp实现2级联动选择菜单

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.myblog.entity.FenLeiTwo" %>
<%	
	List<FenLeiTwo> listFenleiTwo=new ArrayList<FenLeiTwo>();
	List<FenLeiTwo> listFenleiTwo1=(List<FenLeiTwo>)request.getAttribute("fenleiTList1");
	List<FenLeiTwo> listFenleiTwo2=(List<FenLeiTwo>)request.getAttribute("fenleiTList2");
	List<FenLeiTwo> listFenleiTwo3=(List<FenLeiTwo>)request.getAttribute("fenleiTList3");
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title>My JSP 'writeblog.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<script type="text/javascript">
		function selected(obj)
		{
		
		document.form1.fenleiTwoID.length =  0;//选择清零
		  document.form1.fenleiTwoID.options[0]   =  new  Option('==请选择==','');   //给第一个值       
		
			if(obj=="1")
			{
				<%listFenleiTwo=listFenleiTwo1;
				 for( int i=0;i<listFenleiTwo.size();i++)
				 {
				FenLeiTwo fenLeiTwo=listFenleiTwo.get(i);
				%>
				 document.form1.fenleiTwoID.options[<%=i+1%>]   =  new  Option('<%=fenLeiTwo.getFenleiTname()%>','<%=fenLeiTwo.getFenleiTname()%>');
				<%
				}
				%>
				
			}else if(obj=="2")
			{
			<%listFenleiTwo=listFenleiTwo2;
			 for( int i=0;i<listFenleiTwo.size();i++)
				 {
				FenLeiTwo fenLeiTwo=listFenleiTwo.get(i);
				%>
				 document.form1.fenleiTwoID.options[<%=i+1%>]   =  new  Option('<%=fenLeiTwo.getFenleiTname()%>','<%=fenLeiTwo.getFenleiTname()%>');
				<%
				}
				%>
			}
			else if(obj=="3"){ 
			<%listFenleiTwo=listFenleiTwo3;
			 for( int i=0;i<listFenleiTwo.size();i++)
				 {
				FenLeiTwo fenLeiTwo=listFenleiTwo.get(i);
				%>
				 document.form1.fenleiTwoID.options[<%=i+1%>]   =  new  Option('<%=fenLeiTwo.getFenleiTname()%>','<%=fenLeiTwo.getFenleiTname()%>');
				<%
				}
				%>
			}else
			{
			
			}
				
		}
	</script>

  </head>
  
  <body>
  <div align="left">
  
    	<li class="active" id="xieboke">
    	<form name="form1" >
                <h2>写博客</h2> 博客标题:
                <input type="text" name="">
                <br> 所属类别:
                
                <select name="fenleiOneID" onchange="selected(this.options[this.options.selectedIndex].value)">
                <option value="0" >--选择类别--</option>
                    <option  value="1">慢生活</option>
                    <option value="2">文章分享</option>
                    <option value="3">闲言碎语</option>
                </select>
                <br>详细分类:
                <select name="fenleiTwoID">
   <option value="0" >==选择类别==</option>
                </select>
                <br> 博客内容:<br>
                <textarea rows="25"  cols="80" wrap="hard"></textarea><br>
   &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                <input type="submit" value="保存内容" >
                </form>
            </li>
            </div>
  </body>
</html>

猜你喜欢

转载自shine08210920-hotmail-com.iteye.com/blog/2314576