添加新元素后,必须绑定
change
此外,我们还为他们举办了一场活动。尝试以下代码。
function imagePreview() {
$(".userfile").unbind('change').bind("change", function() {
var files = !!this.files ? this.files : [];
if (!files.length || !window.FileReader) return;
if (/^image/.test( files[0].type)){
var reader = new FileReader();
reader.readAsDataURL(files[0]);
reader.onloadend = function(){
//Changed below line as well to show preview next to the changed element
$(this).next(".preview-image").attr('src', this.result);
}
}
});
}
$('#copy-btn').click(function(){
newOne = $('#hide-ele').html();
$('#form-group-wrapper').append(newOne);
imagePreview();
});
$(function() {
imagePreview();
});