页面中的两个下拉列表框:
- <tr>
-
- tdstyle="width:130px" 所在学院:</tdtdstyle="width:100px"selectid="college"style="width:200px"runat="server"onchange="changcollege(this.value)"optionvalue="0" --请选择所在学院学院--
- optionselect> 所在专业:selectid="specialty"style="width:200px"runat="server"onchange="SaveSpecical(this.value)" --请选择所在专业--
- >
JS脚本代码
<scripttype="text/javascript">
- varhttp_request=false;
- functionsend_request(method,url,content,responseType,callback)
- {
- http_request=false;
- if(window.XMLHttpRequest)
- {
- http_request=newXMLHttpRequest();
- if(http_request.overrideMimeType)
- http_request.overrideMimeType("text/xml");
- }
- }
- else
- try
- newActiveXObject("Msxml2.XMLHTTP");
- catch(e)
- newActiveXObject("Microsoft.XMLHTTP");
- {}
- if(!http_request)
- window.alert("创建XMLHttpRequest对象失败");
- returnif(responseType.toLowerCase()=="text")
- http_request.onreadystatechange=callback;
- else
-
- window.alert("ERR");
- if(method.toLowerCase()=="get")
- http_request.open(method,true);
- elseif(method.toLowerCase()=="post")
- http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
- window.alert("Err");
- http_request.send(content);
- functionchangcollege(va)
- if(va!='0')
- varspeciality=document.getElementById("specialty");
- speciality.disabled=varurl="Handler.ashx?type=college&id="+va;
- send_request("GET",null,"text",populateClass3);
- functionpopulateClass3()
- varf=document.getElementById("specialty");
- if(http_request.readyState==4)
- if(http_request.status==200)
- varlist=http_request.responseText;
- varclassList=list.split("|");
- f.options.length=1;
- for(vari=0;i<classList.length;i++)
-
- vartmp=classList[i].split(",");
- f.add(newOption(tmp[1],tmp[0]));
- alert("您所请求的页面有异常。");
- </script>
我们将http请求发送给服务端的Handler.ashx进行处理
publicclassHandler:IHttpHandler
- voidProcessRequest(HttpContextcontext)
- stringtype=context.Request.QueryString["type"];
- if(type.Equals("college"))
- stringid=context.Request.QueryString["id"];
- context.Response.ContentType="text/plain";
- context.Response.Write(getSpecialty(id));
- publicstringgetSpecialty(stringcollege)
- DataSetds=GetInformation.GetSpecialtyInfo(college);
- stringstr="";
- inti=0;i<ds.Tables[0].Rows.Count;i++)
- if(i==ds.Tables[0].Rows.Count-1)
- str+=ds.Tables[0].Rows[i]["SpecialtyID"].ToString()+","+ds.Tables[0].Rows[i]["SpecialtyName"].ToString();
- +ds.Tables[0].Rows[i]["SpecialtyName"].ToString()+"|";
- returnstr.Trim();
- publicboolIsReusable{
- get{
- }
根据学院的编号获得相应的专业,并将专业的名称用“|”分割组合成字符串返回给客户端,客户端脚本拆分字符串添加到下拉框中。
这里只是二级的联动显示,三级联动数据的现实原理是一样的。 (编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|