JavaScript实现省市区三级联动的方法
小编给大家分享一下JavaScript实现省市区三级联动的方法,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
成都创新互联致力于成都网站建设、网站设计,成都网站设计,集团网站建设等服务标准化,推过标准化降低中小企业的建站的成本,并持续提升建站的定制化服务水平进行质量交付,让企业网站从市场竞争中脱颖而出。 选择成都创新互联,就选择了安全、稳定、美观的网站建设服务!
具体内容如下
首先是js
$(document).ready(function(){ getErpMarketByParentCode(0,'province',province); getErpMarketByParentCode(province,'city',city); getErpMarketByParentCode(city,'area',area); getErpMarketByParentCode(area,'market',market); $('#city').append($('
然后是后台方法
@RequestMapping(value = "/getErpMarketByParentCode") public ModelAndView getErpMarketByParentCode(HttpServletRequest request, HttpServletResponse response) throws Exception { String code = request.getParameter("code"); ListerpMarketList = erpMarketService.getErpMarketListByParentCode(code); JSONObject jsonObject = new JSONObject(); jsonObject.put("erpMarketList",erpMarketList); response.getWriter().write(jsonObject.toString()); return null; }
service方法,是从内从中获取省市区这张表
public ListgetErpMarketListByParentCode(String parentCode){ Hashtable erpMarketTable = LoadOnStartService.erpMarketTable;//从内存中获取这张表 List erpMarketList = new ArrayList (); Iterator its = erpMarketTable.keySet().iterator(); while(its.hasNext()){ String key = Util.getString(its.next()); ErpMarket erpMarket = (ErpMarket)erpMarketTable.get(key); if(parentCode.equals(erpMarket.getParentCode())){ erpMarketList.add(erpMarket); } } return erpMarketList; }
省市区的实体类
package com.erp.entity; /** * ErpMarket entity. * * @author MyEclipse Persistence Tools */ public class ErpMarket implements java.io.Serializable { // Fields private String code; private String shortCode; private String name; private String level; private String parentCode; // Constructors /** default constructor */ public ErpMarket() { } /** full constructor */ public ErpMarket(String shortCode, String name, String level, String parentCode) { this.shortCode = shortCode; this.name = name; this.level = level; this.parentCode = parentCode; } // Property accessors public String getCode() { return this.code; } public void setCode(String code) { this.code = code; } public String getShortCode() { return this.shortCode; } public void setShortCode(String shortCode) { this.shortCode = shortCode; } public String getName() { return this.name; } public void setName(String name) { this.name = name; } public String getLevel() { return this.level; } public void setLevel(String level) { this.level = level; } public String getParentCode() { return this.parentCode; } public void setParentCode(String parentCode) { this.parentCode = parentCode; } }
以上是“JavaScript实现省市区三级联动的方法”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注创新互联行业资讯频道!
文章题目:JavaScript实现省市区三级联动的方法
网站URL:http://lswzjz.com/article/ppgddp.html