js實現指定樣式表的顯示

爲頁面設置不同的皮膚就會有不同的.css文件,可以用js實現幾種樣式間的切換

首先 頁面要包含樣式文件的引用,跟平時一樣只是多一些標識

如:
    <link href="../css/General1.css" rel="stylesheet" type="text/css" title="LearningNew1" />


    <link href="../css/General2.css" rel="stylesheet" type="text/css" title="LearningNew2" />


    <link href="../css/General2.css" rel="stylesheet" type="text/css" title="LearningNew3" />

 <link href="<%=ResolveUrl("~/css") %>/ableico.css" rel="stylesheet" type="text/css" />

    <script src="StudyPlanList.js" type="text/javascript"></script>

在StudyPlanList.js 中寫如下代碼

$(document).ready(function() {
 

setActiveStyleSheet("LearningNew2") ;//切換要顯示的樣式

  });

function setActiveStyleSheet(title) {
    var i, a, main;
    for (i = 0; (a = document.getElementsByTagName("link")[i]); i++) {
        if (a.getAttribute("rel").indexOf("style") != -1
        && a.getAttribute("title")) {
            a.disabled = true;
            if (a.getAttribute("title") == title) a.disabled = false;
        }
    }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章