Use JS to get uploaded file name is purely to beautify and use _javascript skills

Source: Internet
Author: User
Why to use JS to get uploaded file name? In fact, purely to beautify, friendly,

However, it is not the same as the Internet, using path.substring (Path.lastindexof ('/') +1);

There are a lot of problems in this kind of work.
For example, the value value of the Firefox input form can be obtained by default, while IE displays the file path.

So to differentiate, under Firefox lastindexof ('/') get is-1, and in IE, the directory shows is a backslash, \, of course, in Linux
, the other browsers get a forward slash/(it is not yet proven that the value obtained by the browser file under Linux will be a full path);

It takes two times to judge:
Copy Code code as follows:

function GetFileName (path) {
var pos1 = path.lastindexof ('/');
var pos2 = path.lastindexof (' \ \ ');
var pos = Math.max (POS1, Pos2)
if (pos<0)
return path;
Else
Return path.substring (pos+1);
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.