1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| $( function(){ // forme abrégée de $(document).ready(function(){
$( "#divImg" ).on( "click", "img", function(){
$( this ).remove();
});
$( "#fileInput" ).on( "change", function( e ){
var w = 0,
file,
img,
reader = new FileReader(),
files = e.target.files,
limite = files.length,
lire = function(){
file = files[ w++ ];
img = document.createElement( "img" );
reader.onload = function( e ){
img.src = reader.result;
$( "#divImg" ).append( img );
};
reader.onloadend = function(){
if ( w < limite ){
lire();
}
};
reader.readAsDataURL( file );
};
if ( limite > 0 ){
lire();
}
});
}); |
Partager