我做了一个二级的省市联动菜单,是客户端的
如果用户修改自己的省份和城市,怎么才能给这个联动菜单赋值呢? 

解决方案 »

  1.   

    where[0] = new comefrom("请选择省份名","请选择城市名", "", "");
    where[1] = new comefrom("北京", "北京", "1", "10"); 
    where[2] = new comefrom("上海", "上海", "2", "21"); 
    where[3] = new comefrom("天津", "天津", "3", "22");
    where[4] = new comefrom("重庆", "重庆", "4", "23"); 
    where[5] = new comefrom("河北", "石家庄|张家口|承德|秦皇岛|唐山|廊坊|保定|沧州|衡水|邢台|邯郸", "5", "311|313|314|335|315|316|312|317|318|319|310"); 
    where[6] = new comefrom("山西", "太原|大同|朔州|阳泉|长治|晋城|忻州|离石|榆次|临汾|运城", "6", "351|352|349|353|355|356|350|358|354|357|359"); 
    where[7] = new comefrom("内蒙古", "呼和浩特(*)|包头|乌海|赤峰|海拉尔|乌兰浩特|通辽|锡林浩特|集宁|东胜|临河|阿拉善左旗", "7", "471|472|473|476|470|482|475|479|474|477|478|483"); 
    where[8] = new comefrom("辽宁", "沈阳(*)|朝阳|阜新|铁岭|抚顺|本溪|辽阳|鞍山|丹东|大连|营口|盘锦|锦州|葫芦岛", "8", "24|421|418|410|413|414|419|412|415|411|417|427|416|429"); 
    where[9] = new comefrom("吉林", "长春(*)|白城|松原|吉林|四平|辽源|通化|白山|延吉", "9", "431|436|438|432|434|437|435|439|433"); 
    where[10] = new comefrom("黑龙江", "哈尔滨(*)|齐齐哈尔|黑河|大庆|伊春|鹤岗|佳木斯|双鸭山|七台河|鸡西|牡丹江|绥化|加格达奇", "10", "451|452|456|459|458|468|454|469|464|467|453|455|457"); 
    where[11] = new comefrom("江苏", "南京(*)|苏州|徐州|连云港|宿迁|淮安|盐城|扬州|泰州|南通|镇江|常州|无锡", "11", "25|512|516|518|527|517|515|514|523|513|511|519|510"); 
    where[12] = new comefrom("浙江", "杭州(*)|湖州|嘉兴|舟山|宁波|绍兴|金华|台州|温州|丽水|衢州", "12", "571|572|573|580|574|575|579|576|577|578|570"); 
    where[13] = new comefrom("安徽", "合肥(*)|宿州|淮北|阜阳|蚌埠|淮南|滁州|马鞍山|芜湖|铜陵|安庆|黄山|六安|巢湖|贵池|宣城", "13", "551|557|561|558|552|554|550|555|553|562|556|559|564|565|566|563"); 
    where[14] = new comefrom("福建", "福州(*)|南平|三明|莆田|泉州|厦门|漳州|龙岩|宁德|福安|邵武|石狮|永安|武夷山", "14", "591|599|598|594|595|592|596|597|593|5930|5990|5950|5980|5991"); 
    where[15] = new comefrom("江西", "南昌(*)|九江|景德镇|鹰潭|新余|萍乡|赣州|上饶|临川|宜春|吉安|抚州", "15", "791|792|798|701|790|799|797|793|794|795|796|7940"); 
    where[16] = new comefrom("山东", "济南(*)|聊城|德州|东营|淄博|潍坊|烟台|威海|青岛|日照|临沂|枣庄|济宁|泰安|莱芜|滨州|菏泽", "16", "531|635|534|546|533|536|535|631|532|633|539|632|537|538|634|543|530"); 
    where[17] = new comefrom("河南", "郑州(*)|三门峡|洛阳|焦作|新乡|鹤壁|安阳|濮阳|开封|商丘|许昌|漯河|平顶山|南阳|信阳|济源|周口|驻马店", "17", "371|398|379|391|373|392|372|393|378|370|374|395|375|377|376|391|394|396"); 
    where[18] = new comefrom("湖北", "武汉(*)|十堰|襄樊|荆门|孝感|黄冈|鄂州|黄石|咸宁|荆州|宜昌|恩施", "18", "27|719|710|724|712|713|711|714|715|716|717|718");
    where[19] = new comefrom("湖南", "长沙(*)|张家界|常德|益阳|岳阳|株洲|湘潭|衡阳|郴州|永州|邵阳|怀化|娄底|吉首", "19", "731|744|736|737|730|733|732|734|735|746|739|745|738|743"); 
    where[20] = new comefrom("广东", "广州(*)|深圳|清远|韶关|河源|梅州|潮州|汕头|揭阳|汕尾|惠州|东莞|珠海|中山|江门|佛山|茂名|湛江|阳江|云浮|肇庆", "20", "20|755|763|751|762|753|768|754|663|660|752|769|756|760|750|757|668|759|662|766|758"); 
    where[21] = new comefrom("广西", "南宁(*)|桂林|柳州|贺州|玉林|钦州|北海|防城港|百色|河池|贵港|梧州", "21", "771|773|772|774|775|777|779|770|776|778|7750|7740"); 
    where[22] = new comefrom("海南", "海口(*)|三亚|儋州", "22", "898|899|890"); 
    where[23] = new comefrom("四川", "成都(*)|广元|绵阳|德阳|南充|广安|遂宁|内江|乐山|自贡|泸州|宜宾|攀枝花|巴中|达州|资阳|雅安", "23", "28|839|816|838|817|826|825|832|833|813|830|831|812|827|818|8320|835"); 
    where[24] = new comefrom("贵州", "贵阳(*)|六盘水|遵义|毕节|铜仁|安顺|凯里|都匀|兴义", "24", "851|858|852|857|856|853|855|854|859"); 
    where[25] = new comefrom("云南", "昆明(*)|曲靖|玉溪|丽江|昭通|思茅|临沧|保山|潞西|泸水|中甸|大理|楚雄|个旧|文山|景洪|红河", "25", "871|874|877|888|870|879|883|875|692|886|887|872|878|873|876|691|8730");
    where[26] = new comefrom("西藏", "拉萨(*)|那曲|昌都|林芝|乃东|日喀则|噶尔", "26", "891|896|895|894|893|892|897"); 
    where[27] = new comefrom("陕西", "西安(*)|延安|铜川|渭南|咸阳|宝鸡|汉中|榆林|商洛|安康", "27", "29|911|919|913|910|917|916|912|914|915"); 
    where[28] = new comefrom("甘肃", "兰州(*)|嘉峪关|白银|天水|酒泉|张掖|金昌|西峰|平凉|定西|陇南|临夏", "28", "931|937|943|938|937|936|935|934|933|932|939|930"); 
    where[29] = new comefrom("宁夏", "银川(*)|石嘴山|吴忠|固原", "29", "951|952|953|954"); 
    where[30] = new comefrom("青海", "西宁(*)|平安|海晏|共和|同仁|玛沁|玉树|德令哈", "30", "971|972|970|974|973|975|976|977"); 
    where[31] = new comefrom("新疆", "乌鲁木齐(*)|克拉玛依|石河子|喀什|阿克苏|和田|吐鲁番|哈密|阿图什|博乐|昌吉|库尔|伊犁|奎屯|塔城|阿勒泰", "31", "991|990|993|998|997|903|995|902|908|909|994|996|999|992|901|906");
      

  2.   

    我在二楼那边发的是一个数组.
    var where = new Array(31); 
    function comefrom(loca, locacity, locaid, locacityids) 

    this.loca = loca; 
    this.locacity = locacity;
    this.locaid = locaid;
    this.locacityids = locacityids;
    }有这个数组还不能做吗?Array包括了省份,市名,省ID,市ID
      

  3.   

    可我是这么生成的:
    页面部分:
    <SCRIPT language="JavaScript">
    <!--
    //以XML求取数据
    //参数:
    //obj,当前动作的下拉框
    //fullName:要填充的下拉框
    function XmlPost(obj,fullName)
    {
    //求取当前下拉框的值
       var svalue = obj.value;
       //定义要填充的对象
       var fullObj = document.all(fullName);
      
       //定义取值地址
       var webFileUrl = "?sortid=" + svalue;
      
       //定义返回值
       var result = "";
      
       //开始取值过程
       var xmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
       xmlHttp.open("POST", webFileUrl, false);
       xmlHttp.send("");
       result = xmlHttp.responseText;   //如果有取到值,则根据格式进行拆分
      //注意如果选择了第一行"请选择"空行时,是取不到值的,因此多加了一个条件
       if(result != "" && svalue != "")
       {
       //先清空原有的值
         fullObj.length=0;
        
         //拆分值成数组
         var piArray = result.split(",");
        
         //循环数组
         for(var i=0;i<piArray.length;i++)
         {
         //再拆分成ID及名称
           var ary1 = piArray[i].toString().split("|");
           //逐一添加项
           fullObj.options.add(new Option(ary1[1].toString(),ary1[0].toString()));
          
         }
       }
       else
       {
         //如果没有取到值,则清空要填充的下拉框的值
         fullObj.length = 0;
         fullObj.options.add(new Option("请选择",""));
       }
    }
    //-->
    </SCRIPT>
    //后台
    private void DownBind1()
    {
    //显示所有的主分类
    DatabaseSql mysql=new DatabaseSql();
    string sql = "select * from category where category_id>2 order by category_id desc ";
    DataTable mytab = mysql.SelectData(sql); //绑定第一个下拉框
    this.DropDownList1.DataSource = mytab;
    this.DropDownList1.DataValueField = "category_id";
    this.DropDownList1.DataTextField = "category_name";
    this.DropDownList1.DataBind(); //添加一个"请选择"行
    this.DropDownList1.Items.Insert(0,new ListItem("请选择分类","")); //为此下拉框添加一个默认选择项(此处默认为sortid = 1
    //做选项时,如果你添加的选定项而此控件中却没有此项,即会出错
    //如:this.mydown1.SelectedValue = "1";
    //所以此处以如下方式进行选定

    ListItem  myItem=new ListItem();
    myItem = this.DropDownList1.Items.FindByValue("3");
    if(myItem != null)
    {
    myItem.Selected = true;
    } //为此下拉框添加选择事件,第一个参数是自己,第二个参数为要填充的下拉框的名称 
    this.DropDownList1.Attributes.Add("onchange","XmlPost(this,'" + this.DropDownList2.ClientID + "');");
    } /// <summary>
    /// 绑定第二个下拉框
    /// </summary>
    private void DownBind2()
    {
    //默认显示分类号为1的所有子类
    DatabaseSql mysql=new DatabaseSql();
       string sql = "select * from subcategory where category_id =3" ;
       DataTable mytab = mysql.SelectData(sql); //绑牢控件
       this.DropDownList2.DataSource = mytab;
       this.DropDownList2.DataSource = mytab;
       this.DropDownList2.DataValueField = "sub_id";
       this.DropDownList2.DataTextField = "sub_name";
       this.DropDownList2.DataBind(); //添加一个空的首行
    this.DropDownList2.Items.Insert(0,new ListItem("请选择名称",""));
    } /// <summary>
    /// 返回第2个下拉框需要的值给xmlhttp
    /// </summary>
    /// <param name="sortid">传递的关键ID值</param>
    private void xmlBind(string sortid)
    {
    DatabaseSql mysql=new DatabaseSql();
    string mystr = "";
    string sql = "select * from subcategory  where category_id= " + sortid ;
    DataTable mytab = mysql.SelectData(sql); //将取到的值形成: ID|名称,ID|名称...这样的形式
    if(mytab.Rows.Count != 0)
    {
    for(int i=0;i<mytab.Rows.Count;i++)
    {
    mystr += "," + mytab.Rows[i]["sub_id"].ToString() + "|" + mytab.Rows[i]["sub_name"].ToString();
    }
    mystr = mystr.Substring(1);
    } //输出页面
    this.Response.Write(mystr);
    this.Response.End(); }