1

以下のjQuery関数を使用して値 petKeysを取得するにはどうすればよいですか?employeeKey

var whenSelectDateFromCalendar = function () {
    initKeyValues();
    petKeys = ? employeeKey = ?
};


var initKeyValues = function () {
    var petKeys = $('#pets input:checked').map(function () {
        return $(this).val();
    }).get().join('+');
    var employeeKey = $('#employee input:checked').map(function () {
        return $(this).val();
    }).get().join('+');
}
4

2 に答える 2

1

オプション 1 - オブジェクト内で複数の結果を返す

var initKeyValues = function () {
    var petKeys = $('#pets input:checked').map(function () {
        return $(this).val();
    }).get().join('+');

    var employeeKey = $('#employee input:checked').map(function () { return $(this).val(); }).get().join('+');}

    return {"petKeys": petKeys,  "employeeKey": employeeKey}
};

var whenSelectDateFromCalendar = function () {
    var result = initKeyValues();

    petKeys = result.petKeys;
    employeeKey = result.employeeKey;   

    // or even...

    petKeys = result["petKeys"];
    employeeKey = result["employeeKey"];
};

オプション 2: 配列内で複数の結果を返す

var initKeyValues = function () {
    var petKeys = $('#pets input:checked').map(function () {
        return $(this).val();
    }).get().join('+');

    var employeeKey = $('#employee input:checked').map(function () { return $(this).val(); }).get().join('+');}

    return [petKeys, employeeKey];
};

var whenSelectDateFromCalendar = function () {
    var result = initKeyValues();

    petKeys = result[0];
    employeeKey = result[1];
};
于 2013-09-10T10:26:27.143 に答える