wjlyt 2014-11-08 05:22 采纳率: 0%
浏览 686

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

控制器内:

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>


  • 写回答

1条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2022-10-29 05:59
    关注
    不知道你这个问题是否已经解决, 如果还没有解决的话:

    如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题