常用省市区无刷新联动实例
1、jquery代码
function getCity(CityVal) { var DDL_Province = $("#DDL_Province"); var DDL_City = $("#DDL_City"); DDL_City.empty(); DDL_City.append("<option value=\"0\">市/区</option>"); $.ajax( { type: "post", url: "/UserCart/Controller/CityAreas.ashx", data: { "type": "city", "provinceID": DDL_Province.val() }, dataType: "json", async: false, success: function (msg) { for (var i = 0; i < msg.length; i++) { if (CityVal == msg[i].CityName) { if (msg[i].IsCOD == 1) { DDL_City.append("<option value=" + msg[i].CityID + " selected=\"selected\">" + msg[i].CityName + "*</option>"); } else { DDL_City.append("<option value=" + msg[i].CityID + " selected=\"selected\">" + msg[i].CityName + "</option>"); } } else { if (msg[i].IsCOD == 1) { DDL_City.append("<option value=" + msg[i].CityID + " >" + msg[i].CityName + "*</option>"); } else { DDL_City.append("<option value=" + msg[i].CityID + " >" + msg[i].CityName + "</option>"); } } } getArea(''); GetAddreesSpan(); } }) }; function getArea(AreaVal) { var DDL_City = $("#DDL_City"); var DDL_Area = $("#DDL_Area"); DDL_Area.empty(); DDL_Area.append("<option value=\"0\">县/乡</option>"); $.ajax( { type: "post", url: "/UserCart/Controller/CityAreas.ashx", data: { "type": "district", "cityID": DDL_City.val() }, dataType: "json", async: false, success: function (msg) { for (var i = 0; i < msg.length; i++) { if (AreaVal == msg[i].DistrictName) { if (msg[i].IsCOD == 1) { DDL_Area.append("<option value=" + msg[i].DistrictID + " selected=\"selected\">" + msg[i].DistrictName + "*</option>"); } else { DDL_Area.append("<option value=" + msg[i].DistrictID + " selected=\"selected\">" + msg[i].DistrictName + "</option>"); } } else { if (msg[i].IsCOD == 1) { DDL_Area.append("<option value=" + msg[i].DistrictID + " >" + msg[i].DistrictName + "*</option>"); } else { DDL_Area.append("<option value=" + msg[i].DistrictID + " >" + msg[i].DistrictName + "</option>"); } } } GetAddreesSpan(); } }) }; function GetAddreesSpan() { }
2、后端C#代码
<%@ WebHandler Language="C#" Class="CityAreas" %> using System; using System.Web; using System.Collections.Generic; public class CityAreas : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; if (context.Request["type"] == "city") { context.Response.Write(select2(context.Request["provinceID"])); } else if (context.Request["type"] == "district") { context.Response.Write(select3(context.Request["cityID"])); } } public string select2(string id) { string str = string.Empty; if (!string.IsNullOrEmpty(id)) { List<ECS.Model.A_CityAreas> list = new ECS.BLL.A_CityAreas().GetList(null, "deep=2 and ParentID=" + id, null); if (list != null && list.Count > 0) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("["); foreach (ECS.Model.A_CityAreas item in list) { sb.Append("{"); sb.Append("\"CityID\":\"" + item.id + "\",\"CityName\":\"" + item.AreaName + "\",\"IsCOD\":\"" + item.IsCOD + "\""); sb.Append("},"); } sb.Remove(sb.Length - 1, 1); sb.Append("]"); str = sb.ToString(); } } return str; } public string select3(string id) { string str = string.Empty; if (!string.IsNullOrEmpty(id)) { List<ECS.Model.A_CityAreas> list = new ECS.BLL.A_CityAreas().GetList(null, "deep=3 and ParentID=" + id, null); if (list != null && list.Count > 0) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("["); foreach (ECS.Model.A_CityAreas item in list) { sb.Append("{"); sb.Append("\"DistrictID\":\"" + item.id + "\",\"DistrictName\":\"" + item.AreaName + "\",\"IsCOD\":\"" + item.IsCOD + "\""); sb.Append("},"); } sb.Remove(sb.Length - 1, 1); sb.Append("]"); str = sb.ToString(); } } return str; } public bool IsReusable { get { return false; } } }

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
Jquery+Json+Handler文件结合应用实例
1、页面script代码-【model数据、字符串】 <script type="text/javascript" charset="utf-8" src="Js/jquery-1.6.2.min.js"></script> <script type="text/javascript"> //提交验证 function ChekFrom() { var msg = ""; //取值 var UserName = $("#txtUserName").val(); //验证 if (UserName == "") { msg += "用户名为空!/r/n"; } else { $.ajax({ type: "POST", url: "/Controller/UserHandler.ashx", data: { Action: "IsUserName", UserName: UserName }, cache: false, //设置时候从浏览器中读取 缓存 true 表示 是 datatype: "json", async: false, success...
- 下一篇
通过ajax记录网站UV、PV数
1、通过jquery记录网站UV、PV数据 util.track = { log: function () { var referrer = util.browser.getReferrer(), host = window.location.host, pathname = window.location.pathname, url = window.location.href, title = document.title, type = 0, itemId = null; var detailRegex = /\/item\/(\d+)/; if (detailRegex.test(pathname)) { var result = detailRegex.exec(pathname); itemId = result[1]; type = 1; $(".js_spec a").click(function () { setTimeout(function () { var skuId = $("#js_skuId").val(); if (skuId != itemId) { ...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- Docker快速安装Oracle11G,搭建oracle11g学习环境
- CentOS8安装Docker,最新的服务器搭配容器使用
- Windows10,CentOS7,CentOS8安装MongoDB4.0.16
- Windows10,CentOS7,CentOS8安装Nodejs环境
- CentOS8编译安装MySQL8.0.19
- SpringBoot2编写第一个Controller,响应你的http请求并返回结果
- SpringBoot2初体验,简单认识spring boot2并且搭建基础工程
- MySQL8.0.19开启GTID主从同步CentOS8
- SpringBoot2全家桶,快速入门学习开发网站教程
- Eclipse初始化配置,告别卡顿、闪退、编译时间过长