lib.itmens/common/static/js/create_update.js

23 lines
665 B
JavaScript
Raw Normal View History

2020-05-01 22:46:15 +08:00
$(document).ready( function() {
// assume there is only one input[file] on page
$("input[type='file']").each(function() {
$(this).after('<img src="#" alt="" id="previewImage" style="margin:10px 0;"/>');
})
// mark required
$("input[required]").each(function() {
$(this).prev().prepend("*");
})
$("input[type='file']").change(function() {
if (this.files && this.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#previewImage').attr('src', e.target.result);
}
reader.readAsDataURL(this.files[0]);
}
});
});