下面的代码只返回第一个if 语句,而不管 var product_check 是否实际上等于另一个 else if 条件。有人能指出我正确的方向吗?我确定它必须是一个简单的修复......
var product_check = '<?php echo($productLine); ?>';
if (product_check === 'Blades' || 'Ceiling Tiles' || 'Clouds' || 'Partitions' || 'Panels') {
jQuery('select#input_6_28 option').html('Acoustical Solutions');
} else if (product_check === 'Curva') {
jQuery('select#input_6_28 option').html('Appliances');
} else if(product_check === 'Acrylic Resin Panels' || 'High Gloss Panels' || 'Super Matte Panels' || 'Modular Cork Wall Panels' || 'Reclaimed Hardwood') {
jQuery('select#input_6_28 option').html('Architectural Panels');
}
您需要单独检查每一项。
试试这个:
var product_check = '<?php echo($productLine); ?>';
if (product_check === 'Blades' || product_check === 'Ceiling Tiles' || product_check === 'Clouds' || product_check === 'Partitions' || product_check === 'Panels') {
jQuery('select#input_6_28 option').html('Acoustical Solutions');
} else if (product_check === 'Curva') {
jQuery('select#input_6_28 option').html('Appliances');
} else if(product_check === 'Acrylic Resin Panels' || product_check === 'High Gloss Panels' ||
product_check === 'Super Matte Panels' || product_check === 'Modular Cork Wall Panels' || product_check ==='Reclaimed Hardwood') {
jQuery('select#input_6_28 option').html('Architectural Panels');
}
使用switch
块会更好。
例子:
switch (product_check) {
case 'Curva':
jQuery('select#input_6_28 option').html('Appliances');
break;
case 'Acrylic Resin Panels':
case 'High Gloss Panels':
case 'Super Matte Panels':
case 'Modular Cork Wall Panels':
case 'Reclaimed Hardwood':
jQuery('select#input_6_28 option').html('Architectural Panels');
break;
default:
jQuery('select#input_6_28 option').html('Acoustical Solutions');
break;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句