在JavaScript网址帮手 [英] URL helper in JavaScript

查看:90
本文介绍了在JavaScript网址帮手的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用jQuery灯箱我的图片库。

该按钮图像的URL是 ../../内容/灯箱/灯箱-BTN-next.gif '

这工作正常,如果我的网址是本地主机/ Something1 / Somtehing2 '

如果我喜欢用另一条路线本地主机/ Something1 / Something2 / Something3 ,那么URL到按钮图像是不正确。

我可以用 Url.Action()里面的.js文件?

这是我如何调用.js文件:

 <脚本类型=文/ JavaScript的SRC =<%= Url.Content(〜/脚本/ jquery.lightbox-0.5.js)%> >< / SCRIPT>


解决方案

您不能使用Url.Action()内的.js文件。但是你可以定义全局变量,并在你的js文件使用它。

 <脚本类型=文/ JavaScript的>    变种图片网址=下;%= ...%>中;< / SCRIPT>

I'm using jQuery Lightbox for my image gallery.
The URL for the button image is '../../Content/Lightbox/lightbox-btn-next.gif'
That works fine if my URL is 'localhost/Something1/Somtehing2'
If I use another route like 'localhost/Something1/Something2/Something3' then URL to button images is incorrect.
Can I use Url.Action() inside .js files?
This is how I call .js files:

<script type="text/javascript" src="<%= Url.Content("~/Scripts/jquery.lightbox-0.5.js") %>"></script>

解决方案

You can't use Url.Action() inside .js files. But you can define global variable and use it in you js file.

<script type="text/javascript">

    var imageUrl = "<%= ... %>";

</script>

这篇关于在JavaScript网址帮手的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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