JQuery+select+C#三级无刷新联动

zxy2543 贡献于2011-06-13

作者 liujiawei  创建于2011-03-22 03:42:00   修改者USER  修改于2011-06-13 07:02:00字数2606

文档摘要:本文档以车辆品牌系列型号三级联动为例。
关键词:

JQuery+select+C# 三级无刷新联动 本文档以车辆品牌系列型号三级联动为例 Default.aspx 页面 头部调用JQuery库和下面的Js文件 需要添加的html代码: 品牌: 系列: 型号: Default.aspx.cs页面代码:(Page_Load) this.car_brand.Items.Clear(); this.car_brand.Items.Add("--请选择--"); this.car_series.Items.Clear(); this.car_series.Items.Add("--请选择--"); this.car_model.Items.Clear(); this.car_model.Items.Add("--请选择--"); IList list1 = Brand.GetBrandList(); foreach (BrandInfo infoin list1) {     this.car_brand.Items.Add(newListItem(info.BrandName,info.BrandId.ToString())); } 需要调用的JS代码: var $ = jQuery.noConflict();  function changeBrand() {     brandid = $("#car_brand").val();     $("#car_series").empty();     $("--请?选?择?--").appendTo($("#car_series"));     $("#car_model").empty();     $("--请?选?择?--").appendTo($("#car_model"));       $.ajax({         type: "post",         url: "/ajax/cars.ashx?type=cb&brandid="+ brandid,         data: "",         success: function(data) {             varstr = data.split("|");             for(var i = 0; i < str.length; i++) {                 varst = str[i].split(",");                 $(""+ st[0].replace("\"", "") + "").appendTo($("#car_series"));             }         }     }); }     function changeSeries() {     seriesid = $("#car_series").val();     $("#car_model").empty();     $("--请?选?择?--").appendTo($("#car_model"));       $.ajax({         type: "post",         url: "/ajax/cars.ashx?type=cs&seriesid="+ seriesid,         data: "",         success: function(data) {             varstr = data.split("|");             for(var i = 0; i < str.length; i++) {                 varst = str[i].split(",");                 $(""+ st[0].replace("\"", "") + "").appendTo($("#car_model"));             }         }     }); } Cars.ashx 代码:(一般处理文件) publicvoid ProcessRequest(HttpContext context)         {             try             {                 String ype = DNTRequest.GetQueryString("type");                 switch(type)                 {                     case"cb":                         int brandid= DNTRequest.GetQueryInt("brandid", 0);                        context.Response.Write(GetSeriesList(brandid));                         break;                     case"cs":                         int seriesid = DNTRequest.GetQueryInt("seriesid", 0);                        context.Response.Write(GetCarModelList(seriesid));                         break;                 }             }             catch{ }         }             Public tring GetSeriesList(intbrandid)         {             stringstr = "";             if(brandid > 0)             {                 IListlist = Chexian.Forum.Series.GetSeriesList(brandid.ToString());                 inti = 0;                 foreach(SeriesInfo info inlist)                 {                     if (i >=1)                         str += "|";                     str += "\"" + info.SeriesName + "," + info.SeriesID.ToString() + "\"";                     i++;                 }             }             returnstr;         }           Public tring GetCarModelList(intseriesid)         {             stringstr = "";             if(seriesid > 0)             {                 IListlist = Chexian.Forum.CarModel.GetCarModelList(seriesid.ToString());                 inti = 0;                 foreach(CarModelInfo info inlist)                 {                     if(i >= 1)                         str += "|";                     str += "\"" + info.ModelName + "," + info.ModelId.ToString() + "\"";                     i++;                 }             }             return str;         } 至此,所有代码和使用方法都已经完毕! 演示地址:http://www.chexian100.com/jisuanqi/index.html

下载文档到电脑,查找使用更方便

文档的实际排版效果,会与网站的显示效果略有不同!!

需要 15 金币 [ 分享文档获得金币 ] 1 人已下载

下载文档