开发者

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

开发者 https://www.devze.com 2023-03-21 01:06 出处:网络
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:

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

精彩评论

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