将 JavaScript 更改事件转换为 jQuery

convert javascript change event to jquery

本文关键字:转换 jQuery 事件 JavaScript      更新时间:2023-09-26

有一个函数可以在HTML 5中处理文件,但它在javascript中我必须将其更改为jquery函数

<style>
  .thumb {
    height: 75px;
    border: 1px solid #000;
    margin: 10px 5px 0 0;
  }
</style>
<input type="file" id="files" name="files[]" multiple />
<output id="list"></output>
<script>
  function handleFileSelect(evt) {
    var files = evt.target.files; // FileList object
    // Loop through the FileList and render image files as thumbnails.
    for (var i = 0, f; f = files[i]; i++) {
      // Only process image files.
      if (!f.type.match('image.*')) {
        continue;
      }
      var reader = new FileReader();
      // Closure to capture the file information.
      reader.onload = (function(theFile) {
        return function(e) {
          // Render thumbnail.
          var span = document.createElement('span');
          span.innerHTML = ['<img class="thumb" src="', e.target.result,
                            '" title="', escape(theFile.name), '"/>'].join('');
          document.getElementById('list').insertBefore(span, null);
        };
      })(f);
      // Read in the image file as a data URL.
      reader.readAsDataURL(f);
    }
  }
  document.getElementById('files').addEventListener('change', handleFileSelect, false);
</script>

这将在本地创建从输入图像翻滚所以我需要更改它才能在 jquery 中工作喜欢这个:

$('#thisfile').change(function(){
handleFileSelect(this)
});

但是当我运行 jquery 函数时,它显示TypeError: evt.target is undefined错误如何在此处提供 jQuery 函数参数?

$('#thisfile').change(function(evt){
    handleFileSelect(evt);
});