像下面这种if
else
用 switch
case
怎么做?
要是弄不了,有什么办法可以简化这种那么多if
else
var linkHref = window.location.href;
if (linkHref.indexOf('product') != -1 && linkHref.indexOf('products') == -1) {
}else if (linkHref.indexOf('products') != -1){
}else if (linkHref.indexOf('video') != -1 && linkHref.indexOf('videos') == -1) {
} else if (linkHref.indexOf('tag') != -1) {
} else if (linkHref.indexOf('coupons') != -1) {
} else if (linkHref.indexOf('order/list') != -1) {
} else if (linkHref.indexOf('order') != -1) {
} else if (linkHref.indexOf('web') != -1) {
}
这种用switch比较直观吧