Доброго дня! Помогите разобраться есть скрипт который при нажатии на кнопку создает элемент <form enctype="multipart/form-data" id="form-upload" style=""><input type="file" name="file" /></form> пытаюсь его отследить чтобы сделать превью файла но не получается Код (Javascript): <script type="text/javascript"><!-- $('.date').datetimepicker({ pickTime: false }); $('.datetime').datetimepicker({ pickDate: true, pickTime: true }); $('.time').datetimepicker({ pickDate: false }); $('button[id^=\'button-upload\']').on('click', function() { var node = this; $('#form-upload').remove(); $('body').prepend('<form enctype="multipart/form-data" id="form-upload" style=""><input type="file" name="file" /></form>'); $('#form-upload input[name=\'file\']').trigger('click'); if (typeof timer != 'undefined') { clearInterval(timer); } timer = setInterval(function() { if ($('#form-upload input[name=\'file\']').val() != '') { clearInterval(timer); $.ajax({ url: 'index.php?route=tool/upload', type: 'post', dataType: 'json', data: new FormData($('#form-upload')[0]), cache: false, contentType: false, processData: false, beforeSend: function() { $(node).button('loading'); }, complete: function() { $(node).button('reset'); }, success: function(json) { $('.text-danger').remove(); if (json['error']) { $(node).parent().find('input').after('<div class="text-danger">' + json['error'] + '</div>'); } if (json['success']) { alert(json['success']); $(node).parent().find('input').val(json['code']); } }, error: function(xhr, ajaxOptions, thrownError) { alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); } }); } }, 500); }); //--></script> Этим скриптом пытаюсь поймать выбранный файл проблема в том что на генерированные элементы он не срабатывает <form enctype="multipart/form-data" id="form-upload" style=""><input type="file" name="file" /></form> Код (Javascript): <script> function handleFileSelect(evt) { var file = evt.target.files; // FileList object var f = file[0]; // Only process image files. if (!f.type.match('image.*')) { alert("Image only please...."); } var reader = new FileReader(); // Closure to capture the file information. reader.onload = (function(theFile) { return function(e) { // Render thumbnail. document.getElementById("outimg").src = e.target.result; }; })(f); // Read in the image file as a data URL. reader.readAsDataURL(f); } document.getElementById('file').addEventListener('change', handleFileSelect, false); </script> На страницу вывожу так HTML: <div class="row"><img style="width:150px; height:100px;" src="" id="outimg"></img></div> Заранее всем спасибо
Код (Javascript): // вариант 1 $(document).on('submit', 'form', function(e) {}); // Вариант 2 при создании узла $(elem).submit(function(e));