爲頁面設置不同的皮膚就會有不同的.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;
}
}
}