上一个斜杠后的jQuery .split()吗? [英] jQuery .split() after last slash?

查看:100
本文介绍了上一个斜杠后的jQuery .split()吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在.split()上找不到太多文档,并且我有一些代码可以通过单击两个单独的按钮来更改图像的源以及图像的目标文件夹.一个按钮更改源文件夹,另一个按钮更改实际的jpeg名称.

I haven't been able to find much documentation on .split(), and I have some code that changes the source of an image and also the target folder of the image on clicking two seperate buttons. One button changes the source folder, the other the actual jpeg name.

我的脚本运行良好,但是现在可以运行了,并且有多个文件夹,当我单击以更改文件夹时,默认图像隐藏/在上一个/之后不显示实际的jpg,直到我单击另一个按钮.我拥有的jQuery如下:

I had the script working fine, but now it's on live and it's multiple folders deep and when i click to change the folder, the default image hides / doesn't display the actual jpg after the last / until i click the other button. the jquery i have is as follows:

$(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');
    });
});

推荐答案

如您所愿,请在最后一个斜杠后添加部分内容: 检查以下代码:

As you want just part after last slash: check the following code:

var t="http://test.test.com/test/test.php";
console.log(t.replace(/^.+\/([^\/]*)$/,'$1'));

这篇关于上一个斜杠后的jQuery .split()吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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