你可以使用$.inArray()
:
var valuesArray = ['QA', 'Efficiency', 'Legal', 'Time', 'BadDebt', 'WriteOff','BusinessInterruption'];
if ($.inArry($(this).val(),valuesArray) !== -1) {
// value is present
}
或者,在支持的浏览器中Array.indexOf()
:
if (valuesArray.indexOf($(this).val()) !== -1) {
// value is present
}
你也可以使用一个简单的开关:
switch($(this).val()) {
case 'QA':
case 'Efficiency':
case 'Legal':
case 'Time':
case 'BadDebt':
case 'WriteOff':
case 'BusinessInterruption':
/* switches continue with all subsequent comparisons until they reach
a `break`, so this function 'doStuff()' will be executed if *any*
of the above match */
doStuff();
break;
default:
noneOfTheAboveMatched();
break;
}
参考: