jQuery.fn.extend({
previewInputImage: function($inputElement, fileIndex){
if(typeof(fileIndex) == 'undefined'){
fileIndex = 0;
}
var $imageElement = $(this);
var input = $inputElement.get(0);
if (input.files && input.files[fileIndex]) {
var reader = new FileReader();
reader.onload = function (e) {
$imageElement.attr('src', e.target.result);
}
reader.readAsDataURL(input.files[fileIndex]);
}
return $(this);
}
});
$('.brand-logo .btn-upload input[type=file]').on('change', function(){
$('.brand-logo .img-thumbnail').previewInputImage($(this));
});
网友评论