我在根据下面的网址制作下拉菜单后,下拉菜单极不稳定,有时选择省后,市级下拉菜单会变,但有时却没反应,不知为什么?
求高人指点......
http://www.cnblogs.com/singlepine/archive/2005/10/19/257954.html

解决方案 »

  1.   

    js有错误,或浏览器问题,用js写的时候,js一旦多的时候总是会出现js错误,刷新浏览器尝试,只要成功一次,说明你程序没有什么大问题!
      

  2.   

    后来发现在出现上述情况后,点击刷新网页,刷新非常缓慢,且无法通过其他连接跳转到别的为网页,现象为点击任何连接没有任何响应,谁能帮助一下。
    我的平台VS2003,SQL2000,使用了AJAX
      

  3.   

    http://blog.csdn.net/lifuyun/archive/2007/09/21/1794085.aspx
    参考资料,望对你有帮助或启示!
      

  4.   

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Car.aspx.cs" Inherits="Car" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>车型、车系性能测试</title>    <script language="javascript" type="text/javascript">
        function changeBrand()
        {
            var context="";
            var arg="Type,"+document.getElementById('brand').value;
            <%= Page.ClientScript.GetCallbackEventReference(this, "arg", "bindType", "context") %>
        }
        function bindType(response)
        {
            eval("List="+response);
            var typeList=document.getElementById('type');
            typeList.options.length   =   0;   //clear   all   
            typeList.options[typeList.options.length]   =   new   Option("请选择",   "0",   true,   true);  
            
             var seriesList=document.getElementById('series');
            seriesList.options.length   =   0;   //clear   all   
            seriesList.options[seriesList.options.length]   =   new   Option("请选择",   "0",   true,   true);   
            
             
            for(var i=0;i<List.length;i++)
            {
                var element=document.createElement("option");
                element.innerText=List[i].Name;
                element.value=List[i].Id;
                typeList.appendChild(element);
            }
        }
        
        function changeType()
        {
            var context="";
            var arg="Series,"+document.getElementById('type').value+","+document.getElementById('brand').value;
            <%= Page.ClientScript.GetCallbackEventReference(this, "arg", "BindSeries", "context") %>
        }
        
        function BindSeries(response)
        {
    //        alert(response);
            eval("List="+response);
            var seriesList=document.getElementById('series');
            seriesList.options.length   =   0;   //clear   all   
            seriesList.options[seriesList.options.length]   =   new   Option("请选择",   "0",   true,   true);   
            for(var i=0;i<List.length;i++)
            {
                var element=document.createElement("option");
                element.innerText=List[i].Name;
                element.value=List[i].Id;
                seriesList.appendChild(element);
            }
        }
        
        function initDropDownList(response)
        {
    //        alert(response);
            eval("List="+response);
            var brandList=document.getElementById('brand');
            brandList.options[brandList.options.length] =   new   Option("请选择",   "0",   true,   true);   
            for(var i=0;i<List.length;i++)
            {
                var element=document.createElement("option");
                if(List[i].Name)
                element.innerText=List[i].Name;
                element.value=List[i].Id;
                brandList.appendChild(element);
            }
        }    
        function InitPage()
        {
            var arg="init";
            var context="";
            <%= Page.ClientScript.GetCallbackEventReference(this, "arg", "initDropDownList", "context") %>
        }
        </script></head>
    <body onload="InitPage()">
        <form id="form1" runat="server">
            <div>
                <select id="brand" name="brand" onchange="changeBrand()">
                </select>
                <select id="type" name="type" onchange="changeType()">
                </select>
                <select id="series" name="series">
                </select>
                <asp:Button ID="btnClear" runat="server" OnClick="btnClear_Click" Text="清空数据" />
                <asp:Button ID="btnCache" runat="server" OnClick="btnCache_Click" Text="生成数据" />
            </div>
        </form>
    </body>
    </html>
      

  5.   

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;public partial class Car : System.Web.UI.Page, ICallbackEventHandler
    {
        DataTable dtFactory = new DataTable("Factory");
        DataColumn dcFactoryId = new DataColumn("ID", Type.GetType("System.Int32"));
        DataColumn dcFactoryName = new DataColumn("Name", Type.GetType("System.String"));    DataTable dtType = new DataTable("Type");
        DataColumn dcTypeId = new DataColumn("ID", Type.GetType("System.Int32"));
        DataColumn dcTypePId = new DataColumn("PID", Type.GetType("System.Int32"));
        DataColumn dcTypeName = new DataColumn("Name", Type.GetType("System.String"));    DataTable dtSeries = new DataTable("Series");
        DataColumn dcSeriesId = new DataColumn("ID", Type.GetType("System.Int32"));
        DataColumn dcSeriesPId = new DataColumn("PID", Type.GetType("System.Int32"));
        DataColumn dcSeriesFId = new DataColumn("FID", Type.GetType("System.Int32"));
        DataColumn dcSeriesName = new DataColumn("Name", Type.GetType("System.String"));    protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
            }
        }    private void FillData()
        {
            for (int i = 0; i < 100; i++)
            {
                DataRow drFactory = dtFactory.NewRow();
                //drFactory["dcFactoryId"] = i;
                drFactory["Name"] = string.Format("品牌{0}", i);
                dtFactory.Rows.Add(drFactory);
                for (int j = 0; j < 20; j++)
                {
                    DataRow drType = dtType.NewRow();
                    drType["ID"] = j;
                    drType["PID"] = i;
                    drType["Name"] = string.Format("品牌{0}车型{1}", i - 1, j);
                    dtType.Rows.Add(drType);
                    for (int k = 0; k < 20; k++)
                    {
                        DataRow drSeries = dtSeries.NewRow();
                        drSeries["FID"] = i;
                        drSeries["PID"] = j;
                        drSeries["Name"] = string.Format("品牌{0}车型{1}车系{2}", i - 1, j, k);
                        dtSeries.Rows.Add(drSeries);
                    }
                }
            }
            if (Cache["Factory"] == null)
            {
                Cache.Insert("Factory", dtFactory, null, DateTime.MaxValue, TimeSpan.Zero);
            }
            if (Cache["Type"] == null)
            {
                Cache.Insert("Type", dtType, null, DateTime.MaxValue, TimeSpan.Zero);
            }
            if (Cache["Series"] == null)
            {
                Cache.Insert("Series", dtSeries, null, DateTime.MaxValue, TimeSpan.Zero);
            }
        }    private void BuiltTable()
        {
            dcFactoryId.AutoIncrement = true;
            dcFactoryId.AutoIncrementSeed = 1;
            dcFactoryId.AutoIncrementStep = 1;        dtFactory.Columns.Add(dcFactoryId);
            dtFactory.Columns.Add(dcFactoryName);        dtType.Columns.Add(dcTypeId);
            dtType.Columns.Add(dcTypePId);
            dtType.Columns.Add(dcTypeName);        dcSeriesId.AutoIncrement = true;
            dcSeriesId.AutoIncrementSeed = 1;
            dcSeriesId.AutoIncrementStep = 1;        dtSeries.Columns.Add(dcSeriesId);
            dtSeries.Columns.Add(dcSeriesPId);
            dtSeries.Columns.Add(dcSeriesFId);
            dtSeries.Columns.Add(dcSeriesName);
        }    #region ICallbackEventHandler 成员    private string eventArgument = string.Empty;    public string GetCallbackResult()
        {
            System.Web.Script.Serialization.JavaScriptSerializer Serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
            string returnValue = string.Empty;
            switch (eventArgument)
            {
                case "init":
                    DataTable dt = (DataTable)Cache["Factory"];
                    Factory[] factories = new Factory[dt.Rows.Count];
                    if (dt.Rows.Count > 0)
                    {
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            factories[i] = new Factory(Convert.ToInt32(dt.Rows[i]["ID"]), dt.Rows[i]["Name"].ToString());
                        }
                    }
                    returnValue = Serializer.Serialize(factories);
                    break;
                default:
                    string[] args = eventArgument.Split(',');
                    if (args[0] == "Type")
                    {
                        DataRow[] drs = ((DataTable)Cache["Type"]).Select("PID=" + args[1]);
                        CarType[] types = new CarType[drs.Length];
                        if (drs.Length > 0)
                        {
                            for (int i = 0; i < drs.Length; i++)
                            {
                                types[i] = new CarType(Convert.ToInt32(drs[i]["ID"]), Convert.ToInt32(drs[i]["PID"]), drs[i]["Name"].ToString());
                            }
                        }
                        returnValue = Serializer.Serialize(types);
                        break;                }
                    else if (args[0] == "Series")
                    {
                        DataRow[] drs = ((DataTable)Cache["Series"]).Select("PID=" + args[1] + "AND FID=" + args[2]);
                        Series[] series = new Series[drs.Length];
                        if (drs.Length > 0)
                        {
                            for (int i = 0; i < drs.Length; i++)
                            {
                                series[i] = new Series(Convert.ToInt32(drs[i]["ID"]), Convert.ToInt32(drs[i]["PID"]), Convert.ToInt32(drs[i]["FID"]), drs[i]["Name"].ToString());
                            }
                        }
                        returnValue = Serializer.Serialize(series);
                        break;
                    }
                    break;
            }
            return returnValue;
        }    public void RaiseCallbackEvent(string eventArgument)
        {
            this.eventArgument = eventArgument;
        }    #endregion    public class Factory
        {
            public Factory(int id, string name)
            {
                this.id = id;
                this.name = name;
            }        int id;        public int Id
            {
                get { return id; }
                set { id = value; }
            }
            string name;        public string Name
            {
                get { return name; }
                set { name = value; }
            }
        }    public class CarType
        {
            public CarType(int id, int pid, string name)
            {
                this.id = id;
                this.pid = pid;
                this.name = name;
            }        int id;        public int Id
            {
                get { return id; }
                set { id = value; }
            }
            int pid;        public int Pid
            {
                get { return pid; }
                set { pid = value; }
            }
            string name;        public string Name
            {
                get { return name; }
                set { name = value; }
            }
        }    public class Series
        {
            public Series(int id, int pid, int fid, string name)
            {
                this.id = id;
                this.pid = pid;
                this.fid = fid;
                this.name = name;
            }        int id;        public int Id
            {
                get { return id; }
                set { id = value; }
            }
            int fid;        public int Fid
            {
                get { return fid; }
                set { fid = value; }
            }
            int pid;        public int Pid
            {
                get { return pid; }
                set { pid = value; }
            }
            string name;        public string Name
            {
                get { return name; }
                set { name = value; }
            }
        }
    }
      

  6.   

        protected void btnClear_Click(object sender, EventArgs e)
        {
            if (Cache["Factory"] == null)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "key", "<script language=javascript>alert('数据已经清空,请勿重复操作')</script>");
                return;
            }
            Cache.Remove("Factory");
            Cache.Remove("Type");
            Cache.Remove("Series");
        }
    protected void btnCache_Click(object sender, EventArgs e)
        {
            if (Cache["Factory"] != null)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "key", "<script language=javascript>alert('数据已经生成,请勿重复操作')</script>");
                return;
            }
            BuiltTable();
            FillData();
        }
      

  7.   


    那么多代码呀
    用ajax或xmlHtml呀