xhj104

无刷新连动菜单1

 1<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="C2C.WebForm1" %>
 2<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
 3<HTML>
 4    <HEAD>
 5        <title>WebForm1</title>
 6        <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
 7        <meta content="C#" name="CODE_LANGUAGE">
 8        <meta content="JavaScript" name="vs_defaultClientScript">
 9        <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
10        <script language="javascript">
11        //jb函数会根据不同的浏览器初始化个xmlhttp对象
12        function jb()
13        {
14           var A=null
15               try 
16               
17                   A=new ActiveXObject("Msxml2.XMLHTTP"); 
18                }
 
19           catch(e)
20           
21                  try 
22                   
23                      A=new ActiveXObject("Microsoft.XMLHTTP"); 
24                   }

25           catch(oc)
26          
27                     A=null 
28                   }
 
29              }
 
30           if ( !&& typeof XMLHttpRequest != "undefined" ) 
31            
32               A=new XMLHttpRequest() 
33             }
 
34           return A 
35        }

36        
37        //下面Go函数是父列表框改变的时候调用,参数是选择的条目
38        function Go(obj)
39        {
40           //得到选择框的下拉列表的value
41          var svalue = obj.value;
42           //定义要处理数据的页面
43           var weburl = "webform1.aspx?parent_id="+svalue;
44           //初始化个xmlhttp对象
45           var xmlhttp = jb();
46           //提交数据,第一个参数最好为get,第三个参数最好为true
47           xmlhttp.open("get",weburl,true);
48          // alert(xmlhttp.responseText);
49           //如果已经成功的返回了数据
50           xmlhttp.onreadystatechange=function()
51           {
52             if(xmlhttp.readyState==4)//4代表成功返回数据
53              {
54                 var result = xmlhttp.responseText;//得到服务器返回的数据
55                 //先清空dListChild的所有下拉项
56                document.getElementById("dListChild").length = 0;
57                 //给dListChild加个全部型号的,注意是Option不是option
58                 document.getElementById("dListChild").options.add(new Option("地区","0"));
59                 if(result!="")//如果返回的数据不是空
60                 {
61                    //把收到的字符串按照,分割成数组
62                    var allArray = result.split(",");
63                   //循环这个数组,注意是从1开始,因为收到的字符串第一个字符是,号,所以分割后第一个数组为空
64                    for(var i=1;i<allArray.length;i++)
65                    {
66                       //在把这个字符串按照|分割成数组
67                      var thisArray = allArray[i].split("|");
68                       //为dListChild添加条目
69                       document.getElementById("dListChild").options.add(new Option(thisArray[1].toString(),thisArray[0].toString()));
70                    }

71                 }

72              }

73           }

74           //发送数据,请注意顺序和参数,参数一定为null或者""
75           xmlhttp.send(null);
76        }

77        
</script>
78    </HEAD>
79    <body MS_POSITIONING="GridLayout">
80        <form id="Form1" method="post" runat="server">
81            <asp:dropdownlist id="dListParent" style="Z-INDEX: 101; LEFT: 248px; POSITION: absolute; TOP: 40px"
82                runat="server" onchange="Go(this)">
83                <asp:ListItem Value="P001">湖南</asp:ListItem>
84                <asp:ListItem Value="P002">湖北</asp:ListItem>
85            </asp:dropdownlist><asp:dropdownlist id="dListChild" style="Z-INDEX: 102; LEFT: 248px; POSITION: absolute; TOP: 104px"
86                runat="server"></asp:dropdownlist><asp:button id="Button1" style="Z-INDEX: 103; LEFT: 256px; POSITION: absolute; TOP: 176px" runat="server"
87                Text="Button"></asp:button></form>
88    </body>
89</HTML>
90

posted on 2006-01-23 15:04  那一片海  阅读(265)  评论(0)    收藏  举报

导航