我有一個腳本工作,根據url切換樣式表。允許通配符在url結尾的JavaScript條件css風格
它必須這樣做,因爲該網站使用smarty模板,我不想改變核心文件或核心css。
現在我必須添加每個單獨頁面的URL路徑名。有更多的頁面,這是不切實際的。
因此,例如,而不是/ojs/index.php/index/user/register
和/ojs/index.php/index/user/profile
我想打電話給/ojs/index.php/index/user/*
所以當時所有頁面/user/
下將應用了樣式表。
這樣做的最好方法是什麼?我看過一些類似的帖子,但並不完全是我需要的。
var loc = window.location;
var currentURL = loc.pathname;
if (currentURL=='/ojs/index.php/index' || currentURL=='/ojs/' || currentURL=='/ojs/index.php/index/about' || currentURL=='/ojs/index.php/index/user/register' || currentURL=='/ojs/index.php/index/user/profile' || currentURL=='/ojs/index.php/index/admin/' || currentURL=='/ojs/index.php/index/admin/auth')
loadjscssfile("/ojs/plugins/themes/main-theme/main-theme.css", "css")
對不起,謝謝你。這工作。非常感謝。將會標記以便其他人可以使用正則表達式找到如何執行此操作或類似操作。 – rootl 2013-07-22 18:44:48
如果我的答案解決了您的問題,那麼我們將不勝感激;-) – 2013-07-23 00:17:46