这就是我所拥有的并且有效:
$(function(){
$('.slide-out-div').tabSlideOut({
tabHandle: '.handle', //class of the element that will become your tab
pathToTabImage: 'http://mhmiisdev2/images/contact_tab.gif', //path to the image for the tab //Optionally can be set using css
imageHeight: '122px', //height of tab image //Optionally can be set using css
imageWidth: '40px', //width of tab image //Optionally can be set using css
tabLocation: 'right', //side of screen where tab lives, top, right, bottom, or left
speed: 300, //speed of animation
action: 'click', //options: 'click' or 'hover', action to trigger animation
topPos: '200px', //position from the top/ use if tabLocation is left or right
leftPos: '20px', //position from left/ use if tabLocation is bottom or top
fixedPosition: true //options: true makes it stick(fixed position) on scroll
});
});
这是我想要的,当我从一个控制器更改为另一个控制器时,它不起作用。注意图像路径不是绝对的
$(function(){
$('.slide-out-div').tabSlideOut({
tabHandle: '.handle', //class of the element that will become your tab
pathToTabImage: '/images/contact_tab.gif', //path to the image for the tab //Optionally can be set using css
imageHeight: '122px', //height of tab image //Optionally can be set using css
imageWidth: '40px', //width of tab image //Optionally can be set using css
tabLocation: 'right', //side of screen where tab lives, top, right, bottom, or left
speed: 300, //speed of animation
action: 'click', //options: 'click' or 'hover', action to trigger animation
topPos: '200px', //position from the top/ use if tabLocation is left or right
leftPos: '20px', //position from left/ use if tabLocation is bottom or top
fixedPosition: true //options: true makes it stick(fixed position) on scroll
});
});
完整性的HTML ...
<div class="slide-out-div">
<a class="handle" href="http://link-for-non-js-users.html">Content</a>
<h3>Medical Variance Reports</h3>
<div>
<ul>
<li><a href="http://mhmssrs2/Reports/Pages/Report.aspx?" target="_blank">Individual Medicines</a></li>
</ul>
</div>
</div>
我怀疑pathToTabImage: /images/contact_tab.gif'
在浏览控制器时会丢失其上下文。帮助我理解......
答案 0 :(得分:2)
我怀疑pathToTabImage:/images/contact_tab.gif'失去了它 浏览控制器时的上下文。
哦,是的,你是对的。在ASP.NET MVC中处理url时始终使用url helper:
pathToTabImage: '@Url.Content("~/images/contact_tab.gif")'
永远不要像在代码中那样对网址进行硬编码。这将确保您的应用程序在虚拟目录下的IIS中部署时可以正常工作。
答案 1 :(得分:0)
只需使用JS中的帮助Url.Content()
函数,就像这样
pathToTabImage: @Url.Content("~/images/contact_tab.gif")
如果您的JS位于外部Javascript文件中,您只需引用一个全局变量。
在视图的顶部:
var myPath = @ Url.Content(“〜/ images /”);
内部外部JS文件:
pathToTabImage: myPath + "contact_tab.gif"
答案 2 :(得分:0)
alert(UrlContent("/hdd/images.gif")); //for debugging purposes
alert(UrlContent("~/hdd/images.gif"));
alert(UrlContent("hdd/images.jpg");
//they all return the correct url
function UrlContent(url) {
// first lets take care of users that are smart
url = $.trim(url.replace("~/", "")); //this should take care of smart users!
if (url.charAt(0) == "/") {
url=url.substring(1,url.length)
}
//now that we have taken care of smart users lets form the url
var UrlPath = location.protocol + '//' + location.hostname +location.port+'/'+url
return UrlPath
}