2016-09-14 50 views
-1

下面的代碼在第3行中被打破,這是因爲等號,但我不確定如何逃避它。有人可以幫我嗎?在JavaScript中跳出等號

if (window.location.href.match(/\/shop\/\?category/)) { 
     jQuery('body').addClass('shop-category'); 
    } else if (window.location.href.match(/\/shop\/\?category=Chef)) { 
     jQuery('body').addClass('shop-category-chef'); 
    } else if (window.location.href.match(new RegExp('/shop/.+'))) { 
     jQuery('body').addClass('shop-item'); 
    } else if (window.location.href.match('/shop/')) { 
     jQuery('body').addClass('shop'); 
    } 
+6

這難道不缺少在最後一個斜槓? –

+1

這裏的等號沒有問題。就像@FabioPoloni所說的,你沒有正確地關閉你的正則表達式。 – BadHorsie

回答

2

第三行缺少一個斜槓:

if (window.location.href.match(/\/shop\/\?category/)) { 
     jQuery('body').addClass('shop-category'); 
    } else if (window.location.href.match(/\/shop\/\?category=Chef/)) { 
     jQuery('body').addClass('shop-category-chef'); 
    } else if (window.location.href.match(new RegExp('/shop/.+'))) { 
     jQuery('body').addClass('shop-item'); 
    } else if (window.location.href.match('/shop/')) { 
     jQuery('body').addClass('shop'); 
    }