ajax动态下拉框的级联操作
来源:互联网 发布:单片机视频教程郭天祥 编辑:程序博客网 时间:2024/05/16 08:24
jsp页面
<td width="7%" align="right" style="padding-top:10px;">市区代码</td><td width="10%" style="padding-top:10px;"><select class="main_select" name="headPageInfo.cityCode"id="headPageInfocityCode" onchange="changeCity(this.value)"><option value="0">--请选择--</option><s:iterator value="cityDic" status="city" id="city"><option value="<s:property value='cityCode'/>"><s:property value="cityName" /></option></s:iterator></select></td><td width="7%" align="right" style="padding-top:10px;">社区代码</td><td width="10%" style="padding-top:10px;"><select class="main_select" name="headPageInfo.belongCode"id="belongCode"><%-- <option value="0">--请选择--</option><s:iterator value="cityDic" status="city" id="city"><option value="<s:property value='cityCode'/>"><s:property value="cityName" /></option></s:iterator> --%></select></td>
js方法
//市区代码,社区代码级联function changeCity(selectedCity){//alert(selectedCity);$("#headPageInfocityCode").val(selectedCity);if(selectedCity=="0"){$("#belongCode").html("");return;}$("#belongCode").html("");var sbelongCode=$("#belongCode");sbelongCode.append('<option value="0">--请选择--</option>');//异步请求查询sbelongCode列表的方法并返回json数组 $.ajax({url : '/headpage/headpage!getBelongCode.htm', type : 'post', data : { citycode : selectedCity }, dataType : 'json', success : function (opts) { // 单选CI if (opts && opts.length > 0) { var html = []; for (var i = 0; i < opts.length; i++) { html.push('<option value="'+opts[i].value+'">'+opts[i].text+'</option>'); } sbelongCode.append(html.join('')); } } });}
后台方法
public void getBelongCode(){try {String citycode=this.getRequest().getParameter("citycode");List<OptionBean> list=headpageService.getBelongCodes(citycode);JSONArray array=JSONArray.fromObject(list);this.getResponse().getWriter().append(array.toString());} catch (IOException e) {e.printStackTrace();}}
注:
将list集合转成json数组时要导入import net.sf.json.JSONArray;
0 0
- ajax动态下拉框的级联操作
- ajax级联下拉框
- ajax 级联下拉框
- 动态级联下拉框
- Ajax+XML实现级联下拉菜单的动态加载
- jquery ajax struts2 级联下拉框 动态生成省市
- AJAX实现级联下拉框
- AJAX实现级联下拉框
- Ajax 实现级联下拉框
- 我的第一记,ajax级联下拉框的实现
- 下拉框级联操作问题
- 不用Ajax实现简单的无刷新级联下拉框
- struts2中用jquery、ajax实现下拉框的级联
- ajax实现无刷屏级联下拉框
- ajax jquery springmvc 级联下拉框
- 级联下拉框 ajax jquery springmvc
- jsp ajax下拉框无限级联动
- 用AJAX做下拉框级联
- arcmap json转feacture
- Java基础之类和对象
- JDK中的设计模式应用实例
- 分享一个比较好用的流式布局的label控件
- Nginx fastcgi_param解释
- ajax动态下拉框的级联操作
- 解决java compiler level does not match the version of the installed java project facet
- 正则表达式里字符串”不包含”匹配技巧
- 查看Chrome浏览器缓存的方法
- Google C++ 编程规范 笔记
- POJ 2377 Bad Cowtractors(最大生成树—prim算法)
- 数据解析的基类
- 【HttpClient4.5中文教程】其他章节及总结
- nginx root