Javascript 刷新视图以应用新选择的主题
我在应用程序中添加了一个Javascript 刷新视图以应用新选择的主题,javascript,jquery,asp.net,asp.net-mvc,Javascript,Jquery,Asp.net,Asp.net Mvc,我在应用程序中添加了一个dropdownlist,用于填充所有可用主题的列表。我在我的_Layout.cshtml页面中添加了这个下拉列表 <div class="col-sm-2"> <div style="float: right;" class="themeSelector" id="themeSelector"> <div style="float: left; margin-top: 10px;"> T
dropdownlist
,用于填充所有可用主题的列表。我在我的_Layout.cshtml页面中添加了这个下拉列表
<div class="col-sm-2">
<div style="float: right;" class="themeSelector" id="themeSelector">
<div style="float: left; margin-top: 10px;">
Theme:
</div>
@Html.DropDownList("themeComboBox", IMCC_PAS.Controllers.AvailableThemes.Themes, new { autopostback = "true", @style = "height:20px; width: 80px;margin-left:5px; margin-top: 8px;" })
</div>
</div>
<div class="col-sm-3">
@Html.Partial("_LoginPartial")
</div>
并根据需要在我的控件上应用主题
但是,当主题发生更改时,如何刷新控件
这就是主题如何应用于页面上的控件
$("fabGrid").jqxGrid({ theme: 'nameOfTheme' });
$("chkAllBtn").jqxButton({ theme: 'nameOfTheme' });
当主题改变时,它应该反映在所有页面上(每个页面都有网格、按钮等)
注意:主题应用于不同的控件(网格、下拉列表、按钮等),可能在
提交表单中,也可能不在中。在\u布局中,加载如下默认主题:
<link rel="stylesheet" href="/content/themes/light.css" id="theme-stylesheet" />
现在,根据下拉值,加载不同的css
文件
问题更改后更新:
如果您想更改jqGrid的主题,它将类似于:
$("#themeComboBox").change(function(){
$("#theme-stylesheet").attr("href", "/content/jqwidgets/styles/" + $(this).val() + ".css");
});
这是一个例子
相对路径将根据您的设置而更改。另外,确保选项中的值与css
文件名匹配。您需要删除当前主题的
,并基于var主题将新的样式表
附加到标题。这些主题css文件是如何命名的?IMCC\u PAS.Controllers.availabletimes.Themes
返回什么?availabletimes
返回主题的SelectList
(主题的字符串名称,如dark
,light
等。主题文件的名称为dark.css
,并捆绑在_布局页面中。这很好,但您能看到编辑过的问题吗?很抱歉,我应该首先提到这一点。@WAQ我不熟悉jqGrid。但是查看他们的文档,您必须执行类似的操作。您需要使用下拉列表中选择的内容更改energyblue
部分。
@WAQ更新了答案。否。在jqxWidget控件中,它不是这样工作的。您可以使用每个控件的theme
属性指定每个控件的主题,就像我在问题的ed中提到的那样ited部分。
$("#themeComboBox").change(function(){
$("#theme-stylesheet").attr("href", "/content/themes/" + $(this).val() + ".css");
});
$("#themeComboBox").change(function(){
$("#theme-stylesheet").attr("href", "/content/jqwidgets/styles/" + $(this).val() + ".css");
});