鍍金池/ 問答/HTML/ Jquery中change方法里傳遞對象 但是只調(diào)用了一次?

Jquery中change方法里傳遞對象 但是只調(diào)用了一次?

我想給一個下拉框賦值:

      <div class="input-control text full-size" data-role="input">
                            <select id="storageInfo" name="storageInfo">
                            </select>
                        </div>

Js:

 //采購change查詢庫房信息
                $("#purchaseEmp").bind("change", function () {
                    /**
                     * 查詢采購員所對應(yīng)的庫房
                     */
                    $.ajax({
                        url: "/DemandPlan/Instock/SelectStorageWithEmp/",
                        dataType: 'JSON',
                        data: {
                            sys_emp_id: $("#purchaseEmp").val().split(',')[0]
                        },
                        type: 'POST',
                        success: function (resp) {
                            if (resp.res != "Failure") {
                                $("#storageInfo").empty();
                                if (resp.res.length == 0) {
                                    $("#storageInfo").append("<option value='none'>請配置庫房...</option>");
                                }
                                $(resp.res).each(function (i, c) {
                                    $("#storageInfo").append("<option value='" + c.wl_storage_id + "," + c.wl_storage_name + "'>" + c.wl_storage_name + "</option>");
                                    // $("#UpdateDeptInfo").append("<option value='" + c.sys_dept_id + "," + c.dept_name + "'>" + c.dept_name + "</option>");
                                });
                                $("#storageInfo").select2();
                                // $("#UpdateDeptInfo").select2();
                            } else {
                                console.log(resp.Msg)
                            }
                        }
                    });
                });

這樣寫是沒問題的,但是我聲明了一個方法然后傳入到里面,
圖片描述

圖片描述

這樣寫,下拉框的change事件只會執(zhí)行一次,然后就沒有效果了。
請告知為什么會這樣?

回答
編輯回答
兮顏

應(yīng)該是:

$("#purchaseEmp").change(function() {
    // 函數(shù)調(diào)用
    selectPurchaseEmp(...);
});

如果 selectPurchaseEmp 沒有參數(shù)的話,可以是:

$("#purchaseEmp").change(selectPurchaseEmp);

change() 的參數(shù)是一個函數(shù)

但你傳入的 change(selectPurchaseEmp(...)) 不是selectPurchaseEmp這個函數(shù),而是 selectPurchaseEmp(...)返回值

2017年4月28日 01:59