开发者

How do I copy a certain part of data from one form field to another in jquery/mootools

I have 2 form input fields one is a image upload one is a text input I need to just take the image file name from the image upload field wit开发者_开发百科hout the /images/and the .jpg


From this post: Need a basename function in Javascript

function baseName(str) {
    var base = new String(str).substring(str.lastIndexOf('/') + 1); 
    if(base.lastIndexOf(".") != -1) 
        base = base.substring(0, base.lastIndexOf("."));
    return base;
}

You can use it by inputting a string into the function like so:

var fileName = baseName("path/to/file/image.jpg");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜