简单的答案,你只需要在你的样式表中做一些额外的指示。
就像一个旁注,基于我对需求的理解,我会做主题设置服务器端,这是我的理解,主题将至少每天活动几个小时。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test Page</title>
<script src="jquery-1.4.2.min.js" type="text/javascript"></script>
<style type="text/css">
* { font-family: "Lucida Grande" , "Lucida Sans Unicode" , Verdana, sans-serif; }
body { font-size: 0.7em; margin: 0; }
div#themeContainer, div#themeContainer div, div#header, div#footer, div#content
{ margin: 0; padding: 0; }
div#content
{ text-align: center; }
div#header
{ height: 103px; background: #88f; }
div#footer
{ height: 60px; background: #f88; }
div#content div.centered
{ margin: 0 auto; width: 900px; text-align: left; height: 200px; background: #ddd; }
div#content div.centered h1
{ margin-top: 0px; }
div.dark
{ background: #ccc; }
div.dark div#header
{ background: #777; }
div.dark div#footer
{ background: #777; }
div.dark div#content div.centered
{ background: #234; color: #ddd; }
div.dark h1
{ color: #efe; }
div.dark a
{ color: #fff; font-weight: bold; }
</style>
</head>
<body>
<div id="themeContainer">
<div id="header">
<p>
Header gumpf</p>
</div>
<div id="content">
<div class="centered">
<div>
<h1>
Header</h1>
<p>
Some text</p>
<a id="changeTheme" href="#">Click here to change theme</a>
</div>
</div>
</div>
<div id="footer">
<p>
Footer gumpf</p>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
$("#changeTheme").click(function() {
var container = $("#themeContainer");
if (container.hasClass("dark"))
container.removeClass("dark")
else
container.addClass("dark");
return false;
});
});
</script>
</body>
</html>
您是否尝试了解它是否可以在没有@import指令的情况下使用,而是使用css规则呢? – 2010-06-09 16:21:42
同意Gaby - MSIE中的@import实现有点麻烦(需要特定的配置并且必须是第一项)...其他浏览器更加宽容... – 2010-06-09 16:24:27
为什么你要用javascript而不是服务器端脚本?当然,您可以根据一天中的时间或用户设置轻松地提供正确的主题?什么是内置的应用程序? – 2010-06-09 21:53:18