下拉框联动

来源:互联网 发布:2016年网络主播招聘 编辑:程序博客网 时间:2024/05/29 18:38
  1. 加载第一个下拉框;
public void findParentMode(){        List<Record> list = new ArrayList<Record>();        list = modelService.findAllParentModel();        setAttr("parentModel", list);    }

2 通过change事件触发

<tr>    <th>请选择栏目:</th>    <td>        <select id="pid"  onchange = "getModelH()">         <#if parentModel?exists>            <option value="${p.modelcode}">${p.modelname}</option>        </#if>        </select>        <select id="mid" onchange="getModelD()" ><option value="0" selected>请选择模块...</option></select>        <select id="did" name = "did"><option value="0" selected>请选择...</option></select>    </td></tr><script language="JavaScript">                        function getModelH(){                        var id = document.myform.pid.value;                        var temp_html;                        var url ="${contextPath}/publish/findModelByParentId";                         var paras = {id: id};                        $.ajaxSetup({                         async : false                     });                         $.post(url,paras,function(data){                             temp_html+="<option value='0'>请选择</option>";                             $(data).each(function(){                             temp_html+="<option value='"+ this.MODELCODE +"'>"+ this.MODELNAME +"</option>"                         });                            $("#mid").html(temp_html);                        });                    }                    function getModelD(){                        var id = document.myform.mid.value;                        var temp_html;                        var url ="${contextPath}/publish/findModelByParentId";                         var paras = {id: id};                        $.ajaxSetup({                         async : false                     });                         $.post(url,paras,function(data){                             temp_html+="<option value='0'>请选择</option>";                             $(data).each(function(){                             temp_html+="<option value='"+ this.MODELCODE +"'>"+ this.MODELNAME +"</option>"                         });                            $("#did").html(temp_html);                        });                    }    </script>

3 根据上级下拉框value,后台做查询操作并数据

public void findModelByParentId(){        String code = getPara("id");        List<Record> list = new ArrayList<Record>();        list = modelService.findModelByParentcode(code);        String s = JsonKit.toJson(list, 10);        renderJson(s);      }
0 0
原创粉丝点击