zoukankan      html  css  js  c++  java
  • springmvc 两个下拉框onchange事件

    jsp页面部分

    <li style="240px"><label style="40px">机构:</label> <select
    style="height:22px" name="Searchinstid" id="Searchinstid" class="instid" onchange="select_inst(this)">        //触发事件
    <option value="0" selected="selected">-请选择-</option>
    <c:forEach items="${insts }" var="inst">
    <option value="${inst.id }"
    <c:if test="${inst.id==Searchinstid}">selected </c:if>>${inst.institutionname }</option>
    </c:forEach>
    </select></li>
    <li style="240px"><label style="40px">店家:</label> <select
    style="height:22px" name="shopid" id="shopid" class="shopselect">
    <option value="0" selected="selected">-请选择-</option>
    <c:forEach items="${shops}" var="shop">
    <option value="${shop.id}"
    <c:if test="${shop.id==shopid}">selected </c:if>>${shop.shopname }
    </option>
    </c:forEach>
    </select></li>

    jquery部分

    //触发机构绑定店家列表
    function select_inst(obj) {
    try {
    var instid = $(obj).parent().children(".instid").val();              //通过class获取触发事件的值
    var shopselect = $(obj).parent().parent().children().children(".shopselect");              //通过class获取触发事件改变相对应的变量
    if (instid != 0) {
    $.ajax({
    url : '${ctx}/account/selectByinstid',
    type : 'post',
    cache : false,
    data : {
    instid : instid
    },
    error : function() {
    alertMsg.warn('请按照提示正确填写!');
    },
    success : function(data) {

    $(shopselect).html("");               //清空绑定下拉框的值
    $(shopselect).append($('<option >', {      
    value : 0,                   
    text : '请选择'
    }));

    if (data != null && data != "") {
    $.each(data, function(i, item) {
    $(shopselect).append($('<option >', {            //循环迭代后台返回的列表
    value : item['id'],                                           
    text : item['shopname'],

    }));

    });

    }
    }
    });
    }
    } catch (e) {
    console.error("我次哦,有异常了~", e);
    }
    }

    ---------------------------------------------------------------------------------------------------------------------------------------------------

    controller部分

    // 通过机构id查询店家列表
    @RequestMapping(value = { "/selectByinstid" }, method = RequestMethod.POST)
    @ResponseBody
    public List<BtyShop> selectByProjectId(
    HttpServletRequest request,
    @RequestParam(value = "instid", defaultValue = "0", required = false) int institutionId) {
    List<BtyShop> shops = btyShopService.getinstidshop(institutionId);
    return shops;              //shops链表即为返回的data对象
    }

    当能力支撑不了野心时,就该静下心来学习!
  • 相关阅读:
    作业五:团队项目——项目启动及需求分析
    结对编程项目---四则运算
    PSP记录个人项目耗时情况
    代码复查
    是否需要有代码规范?
    编写一个能自动生成小学四则运算题目的程序。
    目前流行的源程序版本管理软件和项目管理软件的优缺点
    在Github注册账户
    浏览完整部教材,列出不懂的5-10个问题
    FZU 1683 纪念SlingShot(矩阵水)
  • 原文地址:https://www.cnblogs.com/1234cjq/p/5830024.html
Copyright © 2011-2022 走看看