Method One,
Use regular Expressions:
JS Code
var file=$ ("Input[name= ' file ']"). Val (); var filename=file.replace (/.* (\/|\\)/, ""); var fileext= (/[.) /.exec (filename))? /[^.] +$/.exec (Filename.tolowercase ()): ";
FileName Gets the file name
Fileext Get suffix Name
Method Two,
JS Code
var location=$ ("Input[name= ' file ']"). Val (); var point = Location.lastindexof ("."); var type = LOCATION.SUBSTR (point); if (type== ". jpg" | | type== ". gif" | | type== ". JPG "| | type== ". GIF ") {
Get the file name and suffix:
1. Use Split () to split the array and remove the label 0.
var arr = sfilename.split ('. ');
Alert (arr[0]);
2. Use the general suffix length of 4 features:
var name= sfilename.substr (0,sfilename.length-4)
3. Get the regular expression for the file name:
var sfilename=sfile.replace (/.* (\/|\\)/, "");
Remove suffix:
JS Code
<script > $ (document). Ready (function () { var a=$ ("#image"). attr ("src") alert (A.replace (". png", " ")) }) </script>
How jQuery gets the file suffix