计算机编程

!DOCTYPEhtmlhtmlheadscriptsrc="Major.js"/scriptlinkhref="/bootstrap3.3.7/css/bootstrap.min.css"rel="stylesheet"/scriptsrc="JS/jquery-1.9.1.min.js"/scripttitle专业汇总/title/headbodyform分类divselect/selectselect/select/div/form/body$(function(){//1-5行为网页加载时自动运行的程序$('#button1').click(function(){doRegister();});$('#SelectCollege').change(function(){fillMajor();});fillCollege();});functionfillCollege(){$.post("main.aspx",//要请求的后台网页名{method:'getCollege'},function(data){//后台返回数据data后,执行本大括号内的程序for(vari=0;idata.length;i++){varoption='optionvalue="'+data[i].Region_Code+'"'+data[i].Region_Name+'/option';$('#SelectCollege').append(option);}fillMajor();},"json");}functionfillMajor(){$('#SelectMajor').empty();//先清空列表选项$.post("main.aspx",//要请求的后台网页名{method:'getMajor',college:$('#SelectCollege').val()},function(data){//后台返回数据data后,执行本大括号内的程序for(vari=0;idata.length;i++){varoption='optionvalue="'+data[i].Region_Code+'"'+data[i].Region_Name+'/option';$('#SelectMajor').append(option);}},"json");}publicpartialclassMajor:System.Web.UI.Page{protectedvoidPage_Load(objectsender,EventArgse){}publicvoidgetCollege(){varact=newMAction("Region");DataTabledt=act.Select("Parent_Region_Code='0'");Response.Write(ConvertJson.ToJson(dt));}publicvoidgetMajor(){stringprovince=Request["province"];varact=newMAction("Region");DataTabledt=act.Select("Parent_Region_Code='"+province+"'");Response.Write(ConvertJson.ToJson(dt));}

HTML代码部分:divselectname="province"lay-filter="province"onchange="funpro()"optionvalue=""请选择省/optionoptionvalue="北二"北二/option/select/divdivselectname="floor"lay-filter="floor"onchange="getfloor()"disabledoptionvalue=""请选择市/option/select/divdivselectname="area"lay-filter="area"disabledoptionvalue=""请选择县/区/option/select/divJS代码部分scriptfunctionfunpro(){varselect=document.getElementById("province");for(vari=0;iselect.length;i++)if(select.options[i].selected){vardet_id=select[i].value;//ajax后台获取二级下拉菜单数据$.ajax({type:"post",url:"/get_floor/"+det_id,//$.trim(td0),data:{csrfmiddlewaretoken:'{{csrf_token}}'},dataType:'json',success:function(data){$("#floor").attr("disabled",false);$.each(data,function(index,obj){var$html="";$html+="optionvalue='"+obj+"'"+obj+"/option";$("#floor").append($html);});}});}}functiongetfloor(){//ajax后台获取三级下拉菜单数据varselect=document.getElementById("floor");varpro=document.getElementById("province");for(vari=0;ipro.length;i++)if(pro.options[i].selected){varpro_name=pro[i].value;//二级菜单下拉名alert(pro_name);}for(vari=0;iselect.length;i++)if(select.options[i].selected){varfloor_name=select[i].value;//二级菜单下拉名alert(floor_name);$.ajax({type:"post",url:"/get_area/"+pro_name+'/'+floor_name,//$.trim(td0),data:{csrfmiddlewaretoken:'{{csrf_token}}'},dataType:'json',success:function(data){$("#area").attr("disabled",false);$.each(data,function(index,obj){var$html="";$html+="optionvalue='"+obj+"'"+obj+"/option";$("#area").append($html);});}});}}/script思想很重要一级菜单直接后台给选择一级菜单后调用funpro()函数ajax后台获取数据给二级菜单二级菜单选中后调用getfloor()函数ajax后台获取数据给三级菜单

其他新闻
友情链接

公司名称巴黎人电玩
版权所有:Copyright © 2015-2019 http://www.zhongqiangjy.com. 巴黎人电玩有限公司 版权所有

友情链接

Copyright © 2015-2019 http://www.zhongqiangjy.com. 巴黎人电玩有限公司 版权所有
公司地址http://www.zhongqiangjy.com