扩展到在jquery脚本中包含当前文档名称 [英] Expanding to include current document name in jquery script

查看:84
本文介绍了扩展到在jquery脚本中包含当前文档名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些预加载独立于其扩展的图像的代码,其行为类似于:hover伪类。我的问题是我如何扩大这个包括在源文件的一部分。我的意思是脚本目前将_over添加到现有文件名中,并使扩展名也预加载这些图像。我想要的是它添加/ index_files / filename_imagename_over其中imagename是图像的src。所以它已经增加_over我希望它添加/ index_files /这是静态的和/文件名,它根据文件名称的变化。

  $(function(){$('#nav li a img')。each(function(){
var originalSrc = this.src,
hoverSrc = originalSrc.replace(/ \。( ();

image.src = hoverSrc;

$(this).hover(function(){
image.onload = function(){
}
this.src = hoverSrc;
},function(){
this.src = originalSrc;
});
});
})

我也想知道如果我可以在我的javascript中包含php脚本,我认为我不能处理php,因为它不是.php文件。
这是例子。

如果可以,我可以在脚本中使用它。
我想,也可以简单地使用php的include()作为我的php文档,以便脚本包含在服务器级别,并且处理php代码。

$ b $另一个简单的解决方案是使用图像作为背景(css)和胡佛效果,以改变背景位置。例如, http://www.dynamicsitesolutions.com/css/background-image-switching/


I have some code which preloads images independent of their extension and acts in a way similar to the :hover pseudo class. My question is how can i expand this to include part of the filename in the source. What i mean is the script currently adds _over to the existing filename and leaves the extension also preloading these images. What i want is for it to add /index_files/filename_imagename_over where the imagename is the src of the image. So it already adds _over i want it to add /index_files/ which is static and /filename which changes based on the file name.

$(function() { $('#nav li a img').each(function() {
var originalSrc = this.src,
   hoverSrc = originalSrc.replace(/\.(gif|png|jpe?g)$/, '_over.$1'); 
   image = new Image();

image.src = hoverSrc;

$(this).hover(function() {
  image.onload = function() {
}
  this.src = hoverSrc;
}, function() {
  this.src = originalSrc;
});
});
})

I am also wondering if i can include php script in my javascript, i presume i cant because the server wont process the php because it isn't a .php file. This is the example. If so can i use this in the script. I suppose it would also be possible to simply use a php include() for the javascript into my php document so that the script is included at the server level and the php code is processed.

解决方案

another easy solution would be to use the images as backgrounds (css) and for the hoover effect you change the background position e.g. http://www.dynamicsitesolutions.com/css/background-image-switching/

这篇关于扩展到在jquery脚本中包含当前文档名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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