【问题标题】:css style not working after published发布后CSS样式不起作用
【发布时间】: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 是导入的。我使用了谷歌开发工具,我可以看到访问的类在发布和调试版本中都按预期添加和删除。我刚刚使用了提琴手网络调试器,在运行发布版本时出现错误:将更新帖子

标签: css publish


【解决方案1】:

我不确定,但有时,当我想使用 java 脚本选择一个 id 或类并在母版页中使用内容宫殿持有者时,标签的 id 或类在发布后更改为ContentPlaceHolder_myID。请查看您的源页面。 (如果您使用 ASP.NET,我的解决方案很有用)

我再说一遍,如果你使用 ASP.NET 技术,我所有的 expalins 都会被使用。 如果您在 asp.net 中有母版页和内容页 (http://www.w3schools.com/aspnet/aspnet_masterpages.asp) , 并使用诸如 Lable 之类的 asp.net 标记,运行项目后您的元素 ID 会发生变化,并且您会在元素 ID 的前缀上看到内容页面的 ID。 例如:

<%@ Master %>

<html>
<body>
<h1>Standard Header From Masterpage</h1>
<asp:ContentPlaceHolder id="CPH1" runat="server">
<asp:Label ID="lblTest" runat="server" Text="Label"></asp:Label>
</asp:ContentPlaceHolder>
</body>
</html>

运行项目后你会看到:

 <span id="CPH1_lblTest">Label</span>

编译后的标签标签更改为跨度标签,其ID从lblTest更改为CPH1_lblTest。(右键单击您的网页并选择查看源代码) 现在你应该在你的javascript中使用CPH1_lblTest而不是lblTest。

【讨论】:

  • 我很抱歉哈米德。我不明白你的建议,你能澄清一下吗?
猜你喜欢
  • 2014-06-05
  • 2016-04-02
  • 2017-01-15
  • 1970-01-01
  • 2015-07-14
  • 2017-03-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多