jquery json实现二级动态联动


以下为代码!需要导入json架包
function getCity1(){
var unitid = document.getElementById('addformunitid').value;
$.getJSON("../unit/getcity.do?unitid="+unitid, "", function(response){
//$ ("#departmentid").show();//将隐藏的select显示出来
$ ("#adddepartmentid option").remove();//将select中的信息清空
$ ("#adddepartmentid").attr("disabled",false);
//alert(response);
$.each(response,function(i){
//encodeURI(response[i]);
//encodeURI(fileName)
//将后台传回的信息打印到页面中
$ ("#adddepartmentid").append ("<option value="+response[i].id+">"+ response[i].departmentname +"</option>");
});
});
}
<tr>
<td class="td_title">所属单位<em>*</em></td>
<td>
<select name="eform.unitid" id="addformunitid" onChange="getCity1();">
<option value="0">请选择</option>
<#list unitList as ul>
<option value="${ul.id}">${ul.unitname}</option>
</#list>
</select>
</td>
<td class="td_title">部门<em>*</em></td>
<td>
<select name="eform.departmentid" id="adddepartmentid" disabled="disabled">
<option value=" ">请选择</option>
</select>
</td>
<td class="td_title">职位<em>*</em></td>
<td>
<select name="eform.positionid">
<option value=" ">请选择-</option>
<#list positionList as pl>
<option value="${pl.id}">${pl.positionname}</option>
</#list>
</select>
</td>
</tr>
<!-- 单位,部门二级联动 -->
<package name="unit" extends="webwork-default" namespace="/unit">
<action name="getcity" class="com.hnbus.action.unit.EmployeeJsonAction" method="getcity" >
<interceptor-ref name="defaultStack"/>
</action> </package>
/*
*文件名:EmployeeJsonAction.java
*描 述:二级联动action
*版 权:********有限公司 Copyright (c) 2008-2013,All Rights Reserved.
*创建者:向洁
*修改者:向洁
*/ package com.hnbus.action.unit; import java.io.PrintWriter;
import java.net.URLDecoder;
import java.util.List; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse; import net.sf.json.JSONArray; import org.apache.log4j.Logger;
import org.eps.action.BaseAction; import com.hnbus.model.Department;
import com.hnbus.model.Employee;
import com.hnbus.service.unit.EmployeeService;
import com.opensymphony.webwork.ServletActionContext;
/**
* @Description (二级联动action)
* @author 向洁
* @version JOHOM V1.0
* @Date 2013-8-4-下午10:54:05
* @see
*/
public class EmployeeJsonAction extends BaseAction{ private static final Logger logger = Logger.getLogger(EmployeeAction.class); @Resource
private EmployeeService employeeService;
private EmployeeForm1 eform;
private String unitid; public String getcity() throws Exception {
logger.info("选择单位ID");
//获取前台传来的值
String unitid = this.getRequest().getParameter("unitid"); HttpServletResponse response = ServletActionContext.getResponse();
/*设置字符集为'UTF-8'*/
response.setContentType("text/plain;charset=utf-8");
List<Department> department = employeeService.findSameDepartmentlist(unitid);
ServletActionContext.getRequest().getSession().setAttribute("department",department); //将list转换成JSON对象
JSONArray jr = JSONArray.fromObject(department);
PrintWriter out = this.getResponse().getWriter();
//将JSON对象转换成String类型传入前台
String jsonUser = jr.toString();
out.print(jsonUser);
out.flush();
out.close();
return null;
} /**
* 变量:employeeService
* @return 变量:employeeService
*/
public EmployeeService getEmployeeService() {
return employeeService;
} /**
* 变量:eform
* @return 变量:eform
*/
public EmployeeForm1 getEform() {
return eform;
} /**
* 变量:eform
* @param eform (Set the variable:eform)
*/
public void setEform(EmployeeForm1 eform) {
this.eform = eform;
} /**
* 变量:employeeService
* @param employeeService (Set the variable:employeeService)
*/
public void setEmployeeService(EmployeeService employeeService) {
this.employeeService = employeeService;
} /**
* 变量:logger
* @return 变量:logger
*/
public static Logger getLogger() {
return logger;
} /**
* 变量:unitid
* @return 变量:unitid
*/
public String getUnitid() {
return unitid;
} /**
* 变量:unitid
* @param unitid (Set the variable:unitid)
*/
public void setUnitid(String unitid) {
this.unitid = unitid;
} }
class EmployeeForm1 extends Employee{}
jquery json实现二级动态联动的更多相关文章
- Ajax和JSON完成二级菜单联动的功能
首先需要找好JSON的包哦: 链接:http://pan.baidu.com/s/1jH6gN46 密码:lbh1 1:首先创建一个前台页面,比如secondMenu.jsp,源码如下所示: < ...
- jQuery + json 实现省市区三级联动
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- js 省份城市二级动态联动的例子
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- 《DWZ笔记一》<select>动态联动菜单
联动菜单,即组合框Combo box,在DWZ文档中对组合框combox的是这样描述的: 在传统的select 用class 定义:class=”combox”, html 扩展:保留原有属性name ...
- Json 基于jQuery+JSON的省市联动效果
helloweba.com 作者:月光光 时间:2012-09-12 21:57 标签: jQuery JSON Ajax 省市联动 省市区联动下拉效果在WEB中应用非常广泛,尤其在一些 ...
- 份-城市,基于jQuery的AJAX二级联动,用Struts2整合AJAX【非数据库版】
package loaderman.provincecity; import java.io.IOException; import java.util.LinkedHashSet; import j ...
- JavaScript(jquery)实现二级菜单联动
为什么写这篇随笔? 二级菜单的联动一直是我心中一块石头,犹记得大一的时候只会用一点的Dreamweaver,当时做二级菜单难受啊,啥都不会,网上找了些资料,也看不懂别人的代码更别说用起来了 前些日子. ...
- 省市联动_简单的Demo,适用于各种二级菜单联动
最近搞了一个功能,是查询页面需要用到二级菜单联动,获取到选中的属性value传入到后台. 平常都是用AJAX或者JQuery ,通过XML或者JSON的方式,这样的话需要调用数据库,像典型得到省市联动 ...
- JQuery+Ajax实战三级下拉列表联动(八)
本片文章为练习,项目中不会这样写: 一:涉及到的知识点: jQuery Dom操作 jQuery Ajax操作 ASP.net中的json操作 二:用了自动代码生成器 1.Dal层的代码: publi ...
随机推荐
- CentOS7的一些指令
hostnamectl --static set-hostname yuanxu#永久修改主机名 systemctl stop firewalld.service #停止firewall system ...
- 预备作业02:体会做中学(Learning By Doing)
1.很惭愧,我并没有什么技能能强过大家. 2...... 3.我觉得培养一个技能,必须要通过勤勉的练习,认真的学习,还有不断地结合实践. 4.我觉得我学习<程序设计与数据结构>之后应该对程 ...
- 微服务:如何优雅的使用Mybatis
个人比较喜欢 jpa 这种极简的模式,但是为了项目保持统一性技术选型还是定了 mybatis.到网上找了一下关于 spring boot 和 mybatis 组合的相关资料,各种各样的形式都有,看的人 ...
- 数据预处理:标准化(Standardization)
注:本文是人工智能研究网的学习笔记 常用的数据预处理方式 Standardization, or mean removal and variance scaling Normalization: sc ...
- C# CuttingEdge.Conditions 验证帮助类库 文档翻译
项目主页: https://archive.codeplex.com/?p=conditions 作者博客关于项目的文档(翻译原文): https://www.cuttingedge.it/blogs ...
- JMS异步消息机制
企业消息系统 Java Message Service 是由 Sun Microsystems 开发的,它为 Java 程序提供一种访问 企业消息系统 的方法.在讨论 JMS 之前,我们分来析一下企业 ...
- Contest Reviews(Updating)
现在每天至少一套题又不太想写题解…… 那就开个坑总结下每场的失误和特定题目的技巧吧 2018.8.25[ZROI] T3传送门 T1:找规律找崩了…… 最好不要一上来就钻进大讨论,先想有没有普适规律 ...
- HTTP首部字段
HTTP首部由首部字段名和首部字段值组成,以逗号隔开.如果首部出现重复,有些浏览器优先处理第一个出现的首部,有些优先处理后者. 主要分为四大类 通用首部字段 请求首部字段 响应首部字段 实体首部字段 ...
- java多线程技术之(callable和future)
接着上一篇继续并发包的学习,本篇说明的是Callable和Future,它俩很有意思的,一个产生结果,一个拿到结果. Callable接口类似于Runnable,从名字就可以看出来了,但是Runnab ...
- MAC下安装多版本JDK和切换几种方式
环境: MAC AIR,OS X 10.10,64位 历史: 过去 Mac 上的 Java 都是由 Apple 自己提供,只支持到 Java 6,并且OS X 10.7 开始系统并不自带(而是可选 ...