jquery实现三级联动 +struts2 +ajax

跳转页面代码:

public String indictDetail(){
            。。。。。。。。。。。。。。。。
			// 业务处理
			initProblemType();
			initproblemRespon();
		        return "indictDet。。。。。。。。。。。。。。
	}


后台代码:

public String listTypeone() {
		try {
			if (indictBusiness == null) {
				indictBusiness = new IndictBusiness();
			}
			List<IndictBusiness> list = indictInfoManager.listTypeone(indictBusiness);
			setResult("typeone", list);
		} catch (BusinessException e) {
			logger.error("一级菜单异常!", e);
			setResultMessage("一级菜单异常");
			return ERROR;
		} 
		return SUCCESS;
	}
	public String listTypetwo() {
		JsonOut out=getJsonOut();
		PrintWriter writer ;
		try {
			writer = getHttpServletResponse().getWriter();
			if (indictBusiness == null) {
				indictBusiness = new IndictBusiness();
			}
			List<IndictBusiness> list = indictInfoManager.listTypetwo(indictBusiness);
//			setResult("typetwo", list);
			out.put("typetwoList", list); 
			writer.print(out);
		} catch (BusinessException e) {
			logger.error("二级菜单异常!", e);
			setResultMessage("二级菜单异常");
			return ERROR;
		} catch (IOException e) { 
			logger.error("二级菜单的IO异常!", e);
			setResultMessage("二级菜单的IO异常");
			return ERROR;
		} 
		return null;
	}

html代码:


<!-- 业务信息处理 problemTypeList -->
		<div id="business" style="background-color: #EFEEF5;">	
			<p style="border-bottom:1px solid #DDDDDD"><span style="font-size: 150%;margin: 30px">业务信息</span></p>
		<div class="inline-block pr15" style="width: 5%; clear: both;"></div>
			<div class="inline-block pr5 " style="width: 30%; margin-top: 10px;">
					投诉业务分类
					<select id="problemAttr" name="indictBusiness.problemAttr" onchange="btnSelect1()">  	 				    
					    <option value="">---没有选择---</option>
							#set($problemTypeList=$result.get("problemTypeList"))
							#if($problemTypeList && $problemTypeList.size()>0 )
							#foreach($que in $problemTypeList)
							<option value="$!que.encodeValue"
								#if($!indictInfo.problemAttr==$!que.encodeValue) selected #end>$!que.encodeDesc</option>
							#end #end
					</select>
			</div>
			
			<div class="inline-block pr5 " style="width: 30%; margin-top: 10px;">
					问题定位
					<select id="questionlocate" name="indictBusiness.questionlocate"  onclick="btnSelect2()">				    
					    <option value="">---没有选择---</option>
					</select>
			</div>
			
			<div class="inline-block pr5 " style="width: 30%; margin-top: 10px;">
					问题定责
					<select id="problemRespon" name="indictBusiness.problemRespon" >  	 				    
					    <option value="">---没有选择---</option>
					    #set($problemResponList=$result.get("problemResponList"))
							#if($problemResponList && $problemResponList.size()>0 )
							#foreach($problemRespon in $problemResponList)
							<option value="$!problemRespon.encodeValue"
								#if($!indictBusiness.problemRespon==$!problemRespon.encodeValue) selected #end>$!problemRespon.encodeDesc</option>
							#end #end
					</select>
			</div>
			
			<p style="border-bottom:1px solid #DDDDDD"><span style="font-size: 150%;margin: 30px">问题分类</span></p>
		<div class="inline-block pr15" style="width: 5%; clear: both;"></div>
			<div class="inline-block pr5 " style="width: 30%; margin-top: 10px;">
					一级分类
					<select id="typeone" name="indictBusiness.typeone" onclick="btnType1()" onchange="changeType1()">				    
					    <option value="">---没有选择---</option>
					</select>
			</div>
			<div class="inline-block pr5 " style="width: 30%; margin-top: 10px;">
					二级分类
					<select id="typetwo" name="indictBusiness.typetwo" onclick="btnType2()" onchange="changeType2()">				    
					    <option value="">---没有选择---</option>
					</select>
			</div>
			<div class="inline-block pr5 " style="width: 30%; margin-top: 10px;">
					三级分类
					<select id="typethree" name="indictBusiness.typethree" onclick="btnType3()">				    
					    <option value="">---没有选择---</option>
					</select>
			</div>
		</div>

js代码:

//	投诉业务分类的onchange事件
	function btnSelect1(){
			var tempvalue = $("#problemAttr").val();
			var tempvalue2 = $("#problemAttr").val();
// 			alert(tempvalue);
			var type='';//定位
			var type2=''//分类1
			//对问题定位的改变
			if(tempvalue !=null && tempvalue != ""){
				$("#questionlocate option[value!='']").remove();
				$("#typeone option[value!='']").remove();
// 				$("#questionlocate")加载问题定位
				if(tempvalue=='01'){
					type='indict.question01';
				}else if(tempvalue=='02'){
					type='indict.question02';
				}else if(tempvalue=='03'){
					type='indict.question02';
				}else if(tempvalue=='04'){
					type='indict.question02';
				}else if(tempvalue=='05'){
					type='indict.question05';
				}else if(tempvalue=='06'){
					type='indict.question06';
				}else if(tempvalue=='07'){
					type='indict.question07';
				}else if(tempvalue=='08'){
					type='indict.question02';
				}
			//对一级分类的改变
				if(tempvalue=='01'){
					type2='indict.typeone01';
				}else if(tempvalue=='02'){
					type2='indict.typeone02';
				}else if(tempvalue=='03'){
					type2='indict.typeone02';
				}else if(tempvalue=='04'){
					type2='indict.typeone02';
				}else if(tempvalue=='05'){
					type2='indict.typeone03';
				}else if(tempvalue=='06'){
					type2='indict.typeone04';
				}else if(tempvalue=='07'){
					type2='indict.typeone05';
				}else if(tempvalue=='08'){
					type2='indict.typeone02';
				}
				
				//encodeDict.encodeType=type
				var jsonObj = {
					encodeType : type,
					encodeType2 : type2
				};
// 				alert(jsonObj.encodeType);
				jQuery.ajax({
					type:"POST",
					url:"indict!excuteAjax.do",
					dataType:'json',
					contentType: "application/x-www-form-urlencoded;charset=UTF-8",
					async:false,
					data: jsonObj,
					success: function(result) {
//						alert(result.data);
//						alert(result.msg);
						var list = result.data;
						var typeoneList = result.typeoneList;
						for (var i = 0; i < list.length; i++) {
// 							alert(list[i].encodeDesc);
// 							alert(list[i].encodeValue);
 							$("#questionlocate").append("<option value='"+list[i].encodeValue+"'>"+list[i].encodeDesc+"</option>");
						}
						for (var i = 0; i < typeoneList.length; i++) {
							$("#typeone").append("<option value='"+typeoneList[i].encodeValue+"'>"+typeoneList[i].encodeDesc+"</option>");
						}
					}
				}); 	
			}else{
				$("#questionlocate option[value!='']").remove();
				$("#typeone option[value!='']").remove();
				$("#typetwo option[value!='']").remove();
				$("#typethree option[value!='']").remove();
			}
			
		}
//		问题定位的onclick事件
	function btnSelect2(){
		var tempvalue = $("#problemAttr").val();
		if(tempvalue !=null && tempvalue != ""){
			
		}else{
			alert("请选择投诉业务分类!");
		}
	}	
	//一级分类
	function btnType1(){
		var tempvalue = $("#problemAttr").val();
		if(tempvalue !=null && tempvalue != ""){
			
		}else{
			alert("请选择投诉业务分类!");
		}
		
		
	}	
//	一级分类修改事件
	function changeType1(){
		var typeonevalue = $("#typeone").val().trim();
		if(typeonevalue != null && typeonevalue != ""){
		$("#typetwo option[value!='']").remove();
			var jsonObj = {
					"indictBusiness.twopartid" : typeonevalue
				};
			
			jQuery.ajax({
				type:"POST",
				url:"indict!listTypetwo.do",
				dataType:'json',
				contentType: "application/x-www-form-urlencoded;charset=UTF-8",
				async:false,
				data: jsonObj,
				success: function(result) {
					var typetwoList = result.typetwoList;
					for (var i = 0; i < typetwoList.length; i++) {
						$("#typetwo").append("<option value='"+typetwoList[i].twotypeid+"'>"+typetwoList[i].twotypevalue+"</option>");
					}
				}
			}); 
		}else{
			$("#typetwo option[value!='']").remove();
			$("#typethree option[value!='']").remove();
		}
	}
	//二级分类onclick事件
	function btnType2(){
		var typeonevalue = $("#typeone").val().trim();
		if(typeonevalue !=null && typeonevalue != ""){
			
		}else{
			alert("请选择一级分类!");
		}
	}
	
	//二级分类onchange事件
	function changeType2(){
		var typetwovalue = $("#typetwo").val().trim();
		if(typetwovalue !=null && typetwovalue != ""){
			$("#typethree option[value!='']").remove();
			var jsonObj = {
					"indictBusiness.threepartid" : typetwovalue
				};
			
			jQuery.ajax({
				type:"POST",
				url:"indict!listTypethree.do",
				dataType:'json',
				contentType: "application/x-www-form-urlencoded;charset=UTF-8",
				async:false,
				data: jsonObj,
				success: function(result) {
					var typethreeList = result.typethreeList;
					for (var i = 0; i < typethreeList.length; i++) {
						$("#typethree").append("<option value='"+typethreeList[i].threetypeid+"'>"+typethreeList[i].threetypevalue+"</option>");
					}
				}
			}); 
		}else{
			$("#typethree option[value!='']").remove();
		}
	}
	
	function btnType3(){
		var typetwovalue = $("#typetwo").val().trim();
		if(typetwovalue !=null && typetwovalue != ""){
			
		}else{
			alert("请选择二级分类!");
		}
	}
	
	

转载于:https://my.oschina.net/u/2389884/blog/776202

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值