什么是在JavaScript中使用的图片文件夹 [英] What is the picture folder to use in javascript

查看:87
本文介绍了什么是在JavaScript中使用的图片文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的视图中,我可以从内容"文件夹中拖放并自动获取图片地址.

In my View I can drag and drop from my Content folder and get picture address automatic.

<div style="text-align:center">
    <img src="~/Content/information-button16.png" id="info-@car.Car_ID" />
    <img src="~/Content/center-icon.png" id="center-@car.Car_ID" />
</div>

现在,我正在尝试创建阻止消息,并希望添加等待的游标,但这似乎不起作用,因为内容不是公用文件夹.

Now Im trying to create a block message and want add a waiting cursor but this doesnt seem to work, because Content isnt a public folder.

$('#tabs').block({
    message: '<h1><img src=' 
                   + localpath  
                   + '@Url.Content("/GTracker/Content/busy.gif")' 
                   + ' /> Just a moment...</h1>',
    css: { border: '2px solid #3399ff' }
});

我该怎么办?

推荐答案

似乎找不到快速参考,但是~可以在<img src='~/...@Url.Content("~中使用.它不适用于js文字.

Can't seem to find a quick reference, but ~ can be used on <img src='~/... and in @Url.Content("~. It won't work in a js literal.

如果您的js位于剃须刀.cshtml中,则可以执行以下操作:

If your js is in a razor .cshtml, you can do:

$('#tabs').block({
    message: '<h1><img src=' 
                   + '"'
                   + '@Url.Content("~/GTracker/Content/busy.gif")' 
                   + '"'
                   + ' /> Just a moment...</h1>',
    css: { border: '2px solid #3399ff' }
});

$('#tabs').block({
    message: '<h1><img src="@Url.Content("~/GTracker/Content/busy.gif")" /> Just a moment...</h1>',
    css: { border: '2px solid #3399ff' }
});

相反,如果此代码位于.js文件中,则需要传递翻译后的根路径,通常我会在_layout.cshtml中使用类似的方法来完成此操作:

If, instead, this code is in a .js file, you'll need to pass in the translated root path, I normally do this with something like, in _layout.cshtml:

<head>
    <script>var rootpath = '@Url.Content("~")';</script>

然后您可以在.js中使用rootpath(假设它在上述文件之后)

then you can use rootpath in your .js (assuming it's included after the above)

$('#tabs').block({
    message: '<h1><img src=' 
                   + '"'
                   + rootpath + '/Content/busy.gif' 
                   + '"'
                   + ' /> Just a moment...</h1>',
    css: { border: '2px solid #3399ff' }
});

减少了硬编码的路径,并允许您的网站根据需要移动.

The aleviates hardcoded paths and allows your website to move around as required.

这篇关于什么是在JavaScript中使用的图片文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆