gpt4 book ai didi

jquery - ASP.Net MVC 4 动态加载 css 文件

转载 作者:太空宇宙 更新时间:2023-11-04 14:05:21 25 4
gpt4 key购买 nike

我有一个需要自定义的网站,这意味着我需要根据用户选择的选项更改页面的主题。我需要知道如何根据用户选择更改通过 Layout.cshtml 呈现的 css 文件。

这是我的 layout.cshtml 中的两个 css 文件

@Styles.Render("~/Content/style1.css") -> 主题 1@Styles.Render("~/Content/style2.css") -> 主题 2

我已经分配了两个链接来单击以更改我主页中的 css 文件(链接 1-主题 1,链接 2- 主题 2),但我不知道如何更改它。

我最初的想法是有两个链接,当链接被按下时,它将被发送到一个 Controller ,根据用户使用如果有条件,我想这个想法是不可能的。

请告诉我最好的方法,因为我需要尽快在我的网站上实现这个解决方案。

最佳答案

你可以有一个设置whichStyleFlavor的查询字符串参数:

@{
string whichStyleFlavor = "1";
... some logic to check what they requested and change whichStyleFlavor
}

@Styles.Render("~/Content/style" + whichStyleFlavor + ".css")

或者您可以在客户端通过切换 CSS 标签来完成。

来自 here :

<link id="pagestyle" rel="stylesheet" type="text/css" href="default.css">
<script type="text/javascript">
function swapStyleSheet(sheet){
document.getElementById('pagestyle').setAttribute('href', sheet);
}

关于jquery - ASP.Net MVC 4 动态加载 css 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21172609/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com