Last active
March 16, 2018 13:11
-
-
Save 98o718/659dd814716ac7d1165bc04cc5a7853f to your computer and use it in GitHub Desktop.
File input button value
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // File input button value | |
| // HTML | |
| <input type="file" multiple class="input input--hidden input--add-images" id="add-images" accept="image/*"> | |
| <label class="input input--label input--label-for-add-images input--dark" for="add-images">Выберете файл</label> | |
| // JS | |
| function fileInputValue(input, label){ | |
| var inp = $( input ), | |
| lbl = $( label ); | |
| var file_api = ( window.File && window.FileReader && window.FileList && window.Blob ) ? true : false; | |
| inp.change(function(){ | |
| var file_name; | |
| if( file_api && inp[ 0 ].files[ 0 ] ) | |
| if( inp[0].files.length > 1 ) | |
| file_name = inp[0].files.length.toString() + ' файлов'; | |
| else | |
| file_name = inp[ 0 ].files[ 0 ].name; | |
| else | |
| file_name = inp.val().replace( "C:\\fakepath\\", '' ); | |
| if( ! file_name.length ) | |
| return; | |
| if( lbl.is( ":visible" ) ){ | |
| lbl.text( file_name ); | |
| } | |
| }).change(); | |
| }; | |
| // Usage | |
| fileInputValue('.input--add-images', '.input--label-for-add-images'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment