<div class="col-md-9">
<div class="col-md-4">
<div class="btn
btn-primary">
<input type="file" id="fileImage" />
</div>
<div id="imagePreview" class="thumbnail" style="display:none">
<img class="img-responsive" id="targetImg" />
<div class="caption">
<a href="#" id="btbClear"><i class="glyphicon
glyphicon-trash"></i></a>
<p id="description"> </p>
</div>
</div>
</div>
</div>
<script src="~/Scripts/jquery-1.10.2.js"></script>
<script>
$(document).ready(function () {
$("#fileImage").change(function () {
var file = this.files;
if (file && file[0]) {
PreImage(file[0]);
}
});
var PreImage = function (file) {
var reader = new FileReader;
var image = new Image;
reader.readAsDataURL(file);
reader.onload = function (_file) {
image.src =
_file.target.result;
image.onload = function () {
var height = this.height;
var width = this.width;
var type = file.type;
var size = ~~(file.size /
1024) + "KB";
$("#targetImg").attr('src',
_file.target.result);
$("#description").text("Size" + size + "," + height + "x" + width + "," + type + ",");
$("#imagePreview").show();
}
}
}
$("#btbClear").click(function () {
$("#fileImage").val('');
$("#description").text();
$("#imagePreview").hide();
});
});
</script>
No comments:
Post a Comment