【发布时间】:2014-02-10 08:17:44
【问题描述】:
我有两个 CSS 类:
1.-highlightedsearchresult --> 选中表中的项目
2.-visitedsearchresult --> 标记已经访问过的项目
两者都在我的 Site.css 中定义:
.highlightedsearchresult
{
border: medium solid #009999 !important;
background-color: #FFCC66 !important; /* this should overwrite the background color */
}
.visitedsearchresult
{
/* border: medium solid #FFFFFF !important;#6699CC #cc99cc #99CCFF*/
background-color: #cc99cc !important; /* this should overwrite the background color */
}
我的问题是在本地或服务器上发布网站后,我的visitedsearchresult 没有被应用(highlightedsearchresult 样式在发布时应用OK,因此我知道这不是一个不好的参考我的 Site.css)。 当我在 Visual Studio 2012 下以调试模式运行网站时,两种 css 类样式都按预期应用。
这是应用我的样式的代码:
$('.SearchResultsTable').on('click', 'tr', function () {
var index = this.rowIndex;
if (index == 0) {
return; //this is the header, do nothing
}
$(".highlightedsearchresult").each(function () {
$(this).addClass('visitedsearchresult'); //if item has the highlighted class, add the visited class before we removed the selected class
//alert("add visited class");
});
var state = $(this).hasClass('highlightedsearchresult');
if (!state) {
$(this).removeClass("visitedsearchresult"); //remove our visited class, thus the background is set as selected
$(this).addClass("highlightedsearchresult").siblings().removeClass("highlightedsearchresult");
}
else {
//alert("removing visited class");
$(this).removeClass("visitedsearchresult"); //remove our visited class, thus the background is set as selected
}
var storyUrl = '@Url.Action("StoryDisplay", "DisplayStory")';
var file = $(this).attr('SearchResultFilename'); //get filename from our custom attribute
storyUrl += "?filename=" + file;
$("#divdisplaystory").css("width", "74%");
$("#divsearchresults").css("width", "25%");
$("#divdisplaystory").show();
$('#divdisplaystory').loadWithoutCache(storyUrl);
});
如果有人知道为什么这种特殊风格一旦发布就不起作用,我将不胜感激。任何帮助都非常感谢。
更新 我使用 Fiddler Web Debugger 查看下面发生的情况,发现在访问发布网站时我得到 401:由于身份验证标头无效,您无权查看此页面。我仍然可以使用该网站,并且我的所有其他样式都在应用中。此外,我在屏幕上显示用户名 (@User.Identity.Name),并且它显示为正确的 Domain\UserName。太奇怪了。该站点已禁用匿名身份验证,并已启用 Windows 身份验证
非常感谢
【问题讨论】:
-
更多信息会很棒。您能否向我们展示生成 HTML 的服务器端代码、它在本地呈现的内容以及发布时间(在浏览器中查看源代码)? css是如何包含的? (使用捆绑包?)您使用的是什么技术? (我猜是来自
@Url.Action()的 ASP.NET MVC) -
另外,你为什么用
!important? -
也许你的缓存有问题。尝试使用 ctrl-F5 在浏览器中强制刷新缓存。
-
是的,我使用的是 ASP.NET MVC,css 是导入的。我使用了谷歌开发工具,我可以看到访问的类在发布和调试版本中都按预期添加和删除。我刚刚使用了提琴手网络调试器,在运行发布版本时出现错误:将更新帖子