我想调用另一个 jQuery 函数并传递另一个参数 - 我传递的参数取决于传递给原始函数的参数的名称。所以我可能有这样的事情:
matchedNumbers1 = compareArrays(userNumbers, winningNumbers1, matchedNumbers1);
matchedNumbers2 = compareArrays(userNumbers, winningNumbers2, matchedNumbers2);
matchedNumbers2 = compareArrays(userNumbers, winningNumbers3, matchedNumbers2);
//COMPARE INPUTTED ARRAY OF NUMBERS TO WINNING ARRAYS OF NUMBERS
function compareArrays (userInput, winningNums, matches) {
matches = 0;
allMatchedNumbers.length = 0;
$(userInput).each(function(i) {
$(winningNums).each(function(j) {
if (userInput[i] == winningNums[j]) {
allMatchedNumbers[matches] = userInput[i];
matches++;
}
});
});
switch (winningNums) {
case 'winningNumbers1':
alert("!!!!!");
markMatches(ListItems1);
break;
case 'winningNumbers2':
markMatches(ListItems2);
break;
case 'winningNumbers3':
markMatches(ListItems3);
break;
}
return matches;
}
希望上面的代码能清楚地说明我想要做什么。我尝试使用switch
语句,但这仅比较值而不是传递给函数的原始参数的名称。任何帮助,将不胜感激。