2 wjlyt wjlyt 于 2014.11.08 13:22 提问

Ajax使用-当选中职位类别时,它所对应的父岗位ID就会用复选框方式显示出来
lll

控制器内:

public ModelAndView addPosition() {
    Map<String, Object> map = new HashMap<String, Object>();
    return new ModelAndView("admin/positionAdd",map);
}

public String savePosition(HttpServletRequest request) throws IOException {

    String post_type = request.getParameter("post_type");
    String post_code = request.getParameter("post_code");
    String post_name = request.getParameter("post_name");
    String post_duties = request.getParameter("post_duties");
    String parent_id = request.getParameter("parent_id");
    String check_state = request.getParameter("check_state");
    String check_note = request.getParameter("check_note");
    String state = request.getParameter("state");

    Position position = new Position();
    position.setId(Common.returnUUID());
    position.setPost_type(post_type);
    position.setPost_code(post_code);
    position.setPost_name(post_name);
    position.setPost_duties(post_duties);
    position.setParent_id(parent_id);
    position.setCheck_state(check_state);
    position.setCheck_note(check_note);
    position.setState(state);
    positionService.insert(position);

    return "redirect:positionList.do"; 
}

@RequestMapping("admin/editPosition.do")
public ModelAndView editPosition(ModelMap modelMap, String id) {
    Position position = (Position) positionService.selectByID(id);
    modelMap.put("p", position);
    return new ModelAndView("admin/positionEdit", modelMap);
}


public String editPosition(@ModelAttribute("Position") Position position)
        throws IOException {
    positionService.update(position);
    return "redirect:positionList.do"; }


public String deletePosition(String id) {
    Position position = new Position();
    position.setId(id);
    positionService.delete(position);
    return "redirect:positionList.do"; 
}

public String positionList(HttpSession session,
        HttpServletRequest request,HttpServletResponse response) {
    String post_type = request.getParameter("post_type");
    @SuppressWarnings("unchecked")
    List<Position> pList = this.positionService.selectList(post_type);
    StringBuffer sb= new StringBuffer();
    sb.append("<tr id = 'select'>");
    for (Position position : pList) {
        sb.append("<td> <input type='checkbox' id='position' name='position' value ='"+position.getPost_code()+"'>"
        +position.getPost_name()+ "</td>");
    }
    sb.append("</tr>");
    try {
        response.getWriter().println(sb.toString());
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}

JSP页面:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

添加企业岗位 function changeCK() { var selectedValue = document.getElementById("post_type"); var selectedIndex = selectedValue.selectedIndex; var ajaxUrl = "duiying.do?post_type=" + selectedValue.options[selectedIndex].value; ajaxFunction(ajaxUrl); document.getElementById("scope").style.display = ""; } function getScope() { } function setVals() { var id = document.getElementsByName("position"); var value = ""; var name = ""; for(var i = 0; i < id.length; i++){ if(id[i].checked) value += id[i].value+","; name += id[i].text+","; } //alert(value); document.getElementById("parent_id").value = value;//"111,222"; document.getElementById("temp1").value = name;//"111,222"; document.getElementById("scope").style.display = "none"; } function ajaxFunction(url) { //考虑到不同浏览器的兼容性,所以做出判断。 var xmlHttp; if (window.XMLHttpRequest) { xmlHttp = new XMLHttpRequest(); } else if (window.ActiveObject) { try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { } } } //监控和接受后台传的字符串 xmlHttp.onreadystatechange = function() { if (xmlHttp.readyState == 4 && xmlHttp.status == 200) { var result = xmlHttp.responseText; //document.getElementById("select").html(); //alert(result); $("#select").html(result); //select fenge(result); //"<p><input type='checkbox' id='checkbox' name='${ts.practice_code}' value='${ts.stu_code}' > ${ts.stu_name}+ ${ts.practice_code}</p>"; } }; xmlHttp.open("GET",url,false); xmlHttp.send(null); } //分割解析字符串。 function fenge(neirong) { }


<form name="form1" id="myform" method="post" action="doAddPosition.do">
    <table border="0" width="400">

        <tr>
            <td width="100">职位类别:</td>
            <td width="300"><select name="post_type" id="post_type" onChange="changeCK()">
                    <option value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                    <option value="4">4</option>
            </select></td>
        </tr>
        <tr>
            <td width="100">岗位编码:</td>
            <td width="300"><input type="text" name="post_code" /></td>
        </tr>
        <tr>
            <td width="100">岗位名称:</td>
            <td width="300"><input type="text" name="post_name" /></td>
        </tr>
        <tr>
            <td width="100">岗位职责:</td>
            <td width="300"><input type="text" name="post_duties" /></td>
        </tr>
        <tr>
            <td width="100">父岗位id:</td>
            <td width="300"><input type="text" name="parent_id" /></td>
        </tr>
        <tr>
            <td width="100">审核备注:</td>
            <td width="300"><input type="text" name="check_note" /></td>
        <tr>
            <td width="100">状态:</td>
            <td width="300"><select name="state" id="state">
                    <option value="1">有效</option>
                    <option value="2">无效</option>
            </select>
            </td>

        </tr>
    </table>
    <div id="scope" style="display:none">
            <table>
            <tr id = "select"><td>请选择</td></tr>
            </table>
      <button type="button" onClick="setVals()">确定</button>

    </div>
    <div style="margin-top:20px;">
        <input type="submit" value="保存" />&nbsp;&nbsp;&nbsp;&nbsp;
        <button type="button" onclick="window.location='./positionList.do'">返回</button>
    </div>
</form>


<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">


修改企业岗位 function changeBoxes(action) { var oForm = document.forms["myForm1"]; var oCheckBox = oForm.college; for(var i=0;i<oCheckBox.length;i++) //遍历每一个选项 if(action<0) //反选 oCheckBox[i].checked = !oCheckBox[i].checked; else //action为1是则全选,为0时则全不选 oCheckBox[i].checked = action; }


<form name="form1" method="post" action="doEditPosition.do">
    <input type="hidden" name="id" name="id" value="${p.id}">
    <table border="1" width="400">

        <tr>
            <td width="100">职位类别:</td>
            <td width="300"><input type="text" name="post_type"
                value="${p.post_type}">
            </td>
        </tr>
        <tr>
            <td width="100">岗位编码:</td>
            <td width="300"><input type="text" name="post_code"
                value="${p.post_code}">
            </td>
        </tr>
        <tr>
            <td width="100">岗位名称:</td>
            <td width="300"><input type="text" name="post_name"
                value="${p.post_name}">
            </td>
        </tr>
        <tr>
            <td width="100">岗位职责:</td>
            <td width="300"><input type="text" name="post_duties"
                value="${p.post_duties}" />
            </td>
        </tr>
        <tr>
            <td width="100">父岗位id:</td>
            <td width="300"><input type="text" name="parent_id"
                value="${p.parent_id}" />
            </td>
        </tr>
        <tr>
            <td width="100">审核备注:</td>
            <td width="300"><input type="text" name="check_note"
                value="${p.check_note}" />
            </td>
        </tr>
        <tr>
            <td width="100">状态:</td>
            <td width="300"><input type="text" name="state"
                value="${p.state}" />
            </td>
        </tr>
    </table>

    <div style="margin-top:20px;">
        <input type="submit" value="保存" />&nbsp;&nbsp;&nbsp;&nbsp;
        <button type="button" onclick="window.location='./positionList.do'">返回</button>
    </div>
</form>


Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
企业职位管理系统sql语言
简单但是很很不错的sql代码 企业表 新闻表 职位管理表应聘信息管理表 系统用户管理表 员工表以及存储过程
CheckBox 选中效果 选中子的父自动选中,选中父的子全部选中
CheckBox 选中效果 选中子的父自动选中,选中父的子全部选中 适用于C:Foreach 读取${list} 然后选中的选项添加到数据库
JS实现选中一级复选框相关二级或父级同时被选
JS实现选中一级复选框相关二级或父级同时被选;子级全部选中,父级自动选中;父级选中,子级全部选中。做权限功能可用到。html页面。
分别用DOM方式和jQuery方式判断复选框是否被选中
判断一个复选框是否被选中,当选中该复选框时,提示用户可以继续操作; 我已经阅读了上面的制度。 1. DOM方式如下: window.onload = function () { document.getElementById('cr').onclick = function () { if (this.checked) {
JS复选框checkbox:父复选框全选全取消子选框和子选框选则而父选框自动选中的代码
复选项: 子选项 //父复选框全选全取消子选框             function allselect(){                 obj=document.getElementById("allSelected");                 tagNamesObj=document.getElementsByName("warningTy
人才招聘网行业与职位分类数据表分享
最近在做公司的一个项目,里面包括人才模块,整理了招聘网行业与职位分类数据表分享,数据采集自智联招聘网,做人才网的朋友都用得着,分享给大家!
ajax选中的复选框转数组传到后台
var selectedItems = new Array();  $(':input[class=ids][checked]').each(function() {  selectedItems.push($(this).val());  });  $.ajax({   type: "post",   url: "",   data: {items: s
jQuery选取所有复选框被选中的值并用Ajax异步提交数据
&amp;lt;body&amp;gt; 2 &amp;lt;div&amp;gt; 3 &amp;lt;input type=&quot;checkbox&quot; name=&quot;check&quot; value=&quot;1&quot;/&amp;gt;复选框1 4 &amp;lt;input type=&quot;checkbox&quot; name=&quot;check&quot; value=&quot;2&quot;/&amp;gt;复选框2 5
工作岗位分类标准
工作岗位分类标准的sql文件,MySql版
岗位职责数据库设计
岗位职责Job_Responsibilities 英文描述 类型 长度 是否主键 备注 position_id Integer 10 Y 岗位(职位)编号 position_name String 20 N 岗位名称