我一直没能在.split()上找到很多文档,并且我有一些代码可以在单击两个单独按钮时更改图像的来源以及图像的目标文件夹。一个按钮用于更改源文件夹,另一个用于更改实际的jpeg名称。jQuery .split()在最后一个斜杠后?
我有脚本工作正常,但现在它是实时的,它是多个文件夹深,当我点击更改文件夹,默认图像隐藏/不显示实际jpg后最后/直到我点击其他按钮。 jquery的我有如下:。
$(document).ready(function(){
siteUrl = 'http://webdev.timberwindows.com/wp-content/themes/TimberWindows/images/window-planner/';
imgFldr = 'period-black';
//on hovering the 21 or 24 colour options, change the colour of the image but not the folder
$('#black').click(function(){
$("#pic").attr("src",siteUrl+imgFldr+"/black.jpg");
});
//click the hardware buttons and change the folder where the images are coming from, but not the image itself (by name)
$('#standardBlack').click(function(){
$("#pic").attr("src",'standard-black/'+$("#pic").attr("src").split('/')[1]);
imgFldr = 'standard-black';
});
$("#ironmongery li").click(function(){
$('#ironmongery>li').removeClass('selected');
$(this).addClass('selected');
});
$("#colours li").click(function(){
$('#colours>li').removeClass('selected');
$(this).addClass('selected');
});
});
您的代码看起来不错。你可以发布标记的一部分吗? – ShankarSangoli
是的,这里你去:http://pastebin.me/74fc57b4f094813151564c8ca00a558c注意:这是一个wordpress模板文件。 – tjcss
良好做法 - 多次使用局部变量而不是调用“#pic”。 –