分享个极好的无刷新二级联动下拉列表,同样适用与firefox.doc

上传人:ni****g 文档编号:548609443 上传时间:2024-01-22 格式:DOC 页数:6 大小:35KB
返回 下载 相关 举报
分享个极好的无刷新二级联动下拉列表,同样适用与firefox.doc_第1页
第1页 / 共6页
分享个极好的无刷新二级联动下拉列表,同样适用与firefox.doc_第2页
第2页 / 共6页
分享个极好的无刷新二级联动下拉列表,同样适用与firefox.doc_第3页
第3页 / 共6页
分享个极好的无刷新二级联动下拉列表,同样适用与firefox.doc_第4页
第4页 / 共6页
分享个极好的无刷新二级联动下拉列表,同样适用与firefox.doc_第5页
第5页 / 共6页
点击查看更多>>
资源描述

《分享个极好的无刷新二级联动下拉列表,同样适用与firefox.doc》由会员分享,可在线阅读,更多相关《分享个极好的无刷新二级联动下拉列表,同样适用与firefox.doc(6页珍藏版)》请在金锄头文库上搜索。

1、可能极好的又会带来很多的非议,但是我认为这确实很好,我看了大约20个无刷新的连动下拉列表,他们在Firefox下面就一团糟.为了这个我差不多搞了两天,就是如果提交窗体后如何保持第二个列表框的值,因为通过js 给下拉框添加条目那么他的状态是不会被保存的测试平台:ie6,firefox功能:二级无刷新连动特点:跨浏览器;提交窗体取第二下拉框的值;数据来源于数据库;以XMLhttp来发送请求,实现无刷新请求:如果您能够找到更好的方法请告诉我,非常感谢,您的批评和建议对我是莫大的鼓励webform1.ASPx:WebForm1javascripthttp:/ /jb函数会根据不同的浏览器初始化个xml

2、http对象 function jb() var A=null; try A=new ActiveXObject(Msxml2.XMLHTTP); catch(e) try A=new ActiveXObject(Microsoft.XMLHTTP); catch(oc) A=null if ( !A & typeof XMLHttpRequest != undefined ) A=new XMLHttpRequest() return A /下面Go函数是父列表框改变的时候调用,参数是选择的条目 function Go(obj) /得到选择框的下拉列表的value var svalue =

3、obj.value;/定义要处理数据的页面var weburl = webform1.aspx?parent_id=+svalue;/初始化个xmlhttp对象var xmlhttp = jb();/提交数据,第一个参数最好为get,第三个参数最好为truexmlhttp.open(get,weburl,true); / alert(xmlhttp.responseText);/如果已经成功的返回了数据xmlhttp.()if(xmlhttp.readyState=4)/4代表成功返回数据 var result = xmlhttp.responseText;/得到服务器返回的数据/先清空dLi

4、stChild的所有下拉项document.getElementById(dListChild).length = 0;/给dListChild加个全部型号的,注意是Option不是optiondocument.getElementById(dListChild).options.add(new Option(全部型号,0);if(result!=)/如果返回的数据不是空 /把收到的字符串按照,分割成数组 var allArray = result.split(,);/循环这个数组,注意是从1开始,因为收到的字符串第一个字符是,号,所以分割后第一个数组为空 for(var i=1;iallAr

5、ray.length;i+) /在把这个字符串按照分割成数组 var thisArray = allArray.split();/为dListChild添加条目document.getElementById(dListChild).options.add(new Option(thisArray1.toString(),thisArray0.toString(); /发送数据,请注意顺序和参数,参数一定为null或者xmlhttp.send(null); 摩托罗拉诺基亚 后台webform1.aspx.cs:using System;using System.Collections;using

6、 System.ComponentModel;using System.Data;using System.Drawing;using System.Web;using System.Web.SessionState;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.HtmlControls;using System.Configuration;using System.Data.SqlClient;namespace drop/ / WebForm1 的摘要说明。/ public class Web

7、Form1 : System.Web.UI.Pageprotected System.Web.UI.WebControls.DropDownList dListParent;protected System.Web.UI.WebControls.Button Button1;protected System.Web.UI.WebControls.DropDownList dListChild;private void Page_Load(object sender, System.EventArgs e) / 在此处放置用户代码以初始化页面 /if(!IsPostBack) /BindDrop

8、();/如果不是提交回来就绑定列表框 /protected void BindDrop() /首先我想父dropdownlist也绑定数据库,后面想没必要 /if(!IsPostBack) /绑定父dListParent / BindParent(); / /获得传递过来的parent_id值,如果是第一次请求他为null string str = Request.QueryStringparent_id; string str1 = dListParent.SelectedValue; Response.Write(str1); /如果str加个字符串!=原来的字符串则说明触发过dListParent的onchange事件 if(str+abc)!=abc) /绑定 dL

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 科普知识

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号