English 中文(简体)
CSS 文件中的硬编码 URL
原标题:Hard coded URLs in CSS file

我正在研究的项目在 CSS 文件中有硬编码的 URL, 像这样 :

a.edit
{
    background: url(/TestSite/Images/Edit.png) no-repeat top left;
    display: inline-block;
    width: 16px;
    height: 16px;
    padding:1px;
    margin:1px;
    text-indent: -9999px; /* hides the link text */
}

当该站点被移动到生产点时, 这些链接断开。 我在找一个解决方案, 所以它只要运行到网站运行的地方就可以工作 。

这就是我想出来的,它的工作原理, 但我想知道是否有更好的方法:

<script>
    $(document).ready(function () {
        $("a.edit").css( background ,  url(  + $("body").data("baseurl") +  Images/Edit.png) no-repeat top left );
    });
</script>
<body data-baseurl="~/">...</body>
最佳回答

CSS 处理相对样式表位置相对的 URLS 。 利用它, 不用 javastrict 重写 URL 。

问题回答

在生产和开发服务器上使用相同的文件夹结构。并使用相对路径

无法真正理解您所面临的问题是什么。 使用相对路径而不是绝对路径, 您不会有事, 无论主机提供商...

Btw,还有一件事需要考虑 - - 如果客户关闭了 Javamart?

https://stackoverflow.com/ questions/940451/using-relimative-url-in-cs-file-what-place-is-it-relative-to"?

a.edit
{
    background: url(Images/Edit.png) no-repeat top left;
    ...
}




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签