【发布时间】:2012-03-20 16:07:21
【问题描述】:
我想在用户选择时更改我的网页主题 我正在使用 MVC3。 我的想法是在 Content 文件夹中包含各种样式表,并让 _layout.cshtml 文件决定在用户选择时调用哪个 css 文件 目前我所能做的就是包含一个反映在所有页面上的标签 我希望视图相同,但样式表应在选择时更改。
我在 _Layout.cshtml 中尝试了这段代码:
<script type="text/javascript">
function loadjscssfile(filename) {
var fileref = document.createElement("link")
fileref.setAttribute("rel", "stylesheet")
fileref.setAttribute("type", "text/css")
fileref.setAttribute("href", filename)
}
if (typeof fileref != "undefined")
document.getElementsByTagName("head")[0].appendChild(fileref)
内体标签:
<select>
<option onclick="loadjscssfile("@Url.Content("~/Content/Site1.css")")">Theme1</option>
<option onclick="loadjscssfile("@Url.Content("~/Content/Site2.css")")">Theme2</option>
</select>
但这也行不通:( 请帮助我。我是 MVC3 的新手...
【问题讨论】:
标签: css asp.net-mvc-3 model-view-controller