[更新代碼再次] 我有以下代碼:的jQuery - 添加基於URL和無URL類
var header_url = window.location.href;
if(/index/.test(header_url)||/home/.test(header_url)){
$('#home').addClass('select');
} else if(/about/.test(header_url)) {
$('#about').addClass('select');
} else if(/contact/.test(header_url)) {
$('#contact').addClass('select');
}
的代碼的工作,當我點擊他們:
http://example.com/index.html
http://example.com/about.html
http://example.com/contact.html
但如果我想要添加另一個頁面,請將其設置爲默認主頁,而不使用url,如下所示:
http://example.com
我嘗試添加代碼但它不起作用:
else if(/.test(header_url)) {
$('#default').addClass('select');
}
任何人都可以幫忙嗎?謝謝!在開關的情況下
使用''中之開關default'情況下 – Tushar
@Tushar對不起,我貼錯碼,可以請你再檢查? –
然後在末尾添加一個'else'並將其用於'default'的情況 – Tushar