<i id='sS6uq'><tr id='sS6uq'><dt id='sS6uq'><q id='sS6uq'><span id='sS6uq'><b id='sS6uq'><form id='sS6uq'><ins id='sS6uq'></ins><ul id='sS6uq'></ul><sub id='sS6uq'></sub></form><legend id='sS6uq'></legend><bdo id='sS6uq'><pre id='sS6uq'><center id='sS6uq'></center></pre></bdo></b><th id='sS6uq'></th></span></q></dt></tr></i><div id='sS6uq'><tfoot id='sS6uq'></tfoot><dl id='sS6uq'><fieldset id='sS6uq'></fieldset></dl></div>
    <tfoot id='sS6uq'></tfoot>

          <bdo id='sS6uq'></bdo><ul id='sS6uq'></ul>

        <legend id='sS6uq'><style id='sS6uq'><dir id='sS6uq'><q id='sS6uq'></q></dir></style></legend>

        <small id='sS6uq'></small><noframes id='sS6uq'>

        上传前拖放图像输入文件和预览

        时间:2023-11-30

      1. <tfoot id='stydQ'></tfoot>

        <i id='stydQ'><tr id='stydQ'><dt id='stydQ'><q id='stydQ'><span id='stydQ'><b id='stydQ'><form id='stydQ'><ins id='stydQ'></ins><ul id='stydQ'></ul><sub id='stydQ'></sub></form><legend id='stydQ'></legend><bdo id='stydQ'><pre id='stydQ'><center id='stydQ'></center></pre></bdo></b><th id='stydQ'></th></span></q></dt></tr></i><div id='stydQ'><tfoot id='stydQ'></tfoot><dl id='stydQ'><fieldset id='stydQ'></fieldset></dl></div>

        <legend id='stydQ'><style id='stydQ'><dir id='stydQ'><q id='stydQ'></q></dir></style></legend>
            1. <small id='stydQ'></small><noframes id='stydQ'>

                <bdo id='stydQ'></bdo><ul id='stydQ'></ul>
                  <tbody id='stydQ'></tbody>
                  本文介绍了上传前拖放图像输入文件和预览的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想创建一个 div 附加拖放功能,当有人点击它时,他们可以选择他们的图像.

                  I want to create a div attach drag drop feature and when someone click it they can choose their image.

                  我已经编码了一些东西,它可以- 单击 div 并选择您的图像- 上传前预览图片

                  I have coded something and its can - click div and choose your image - preview your image before upload

                  你可以看看我的小提琴

                  css

                  .uploader {width:300px;height:350px;background:#f3f3f3;border:2px dashed #e8e8e8;}
                  

                  javascript

                      var imageLoader = document.getElementById('filePhoto');
                      imageLoader.addEventListener('change', handleImage, false);
                  
                  function handleImage(e) {
                      var reader = new FileReader();
                      reader.onload = function (event) {
                  
                          $('.uploader').html( '<img width="300px" height="350px" src="'+event.target.result+'"/>' );
                      }
                      reader.readAsDataURL(e.target.files[0]);
                  }
                  

                  html

                  <div class="uploader" onclick="$('#filePhoto').click()">click here or drag here your images for preview and set userprofile_picture data</div>
                              <input type="file" name="userprofile_picture"  id="filePhoto" style="display:block;width:185px;"  />
                  

                  你可以检查http://jsfiddle.net/ELcf6/

                  推荐答案

                  你可以用一点 css 技巧来做到这一点.输入元素接受丢弃.我更改了您的代码,如下所示:

                  You can do this with little css tricks. input element accepts drop. I changed your code like below:

                  css

                  .uploader {
                      position:relative; 
                      overflow:hidden; 
                      width:300px; 
                      height:350px;
                      background:#f3f3f3; 
                      border:2px dashed #e8e8e8;
                  }
                  
                  #filePhoto{
                      position:absolute;
                      width:300px;
                      height:400px;
                      top:-50px;
                      left:0;
                      z-index:2;
                      opacity:0;
                      cursor:pointer;
                  }
                  
                  .uploader img{
                      position:absolute;
                      width:302px;
                      height:352px;
                      top:-1px;
                      left:-1px;
                      z-index:1;
                      border:none;
                  }
                  

                  javascript

                  var imageLoader = document.getElementById('filePhoto');
                  imageLoader.addEventListener('change', handleImage, false);
                  
                  function handleImage(e) {
                      var reader = new FileReader();
                      reader.onload = function (event) {
                          $('.uploader img').attr('src',event.target.result);
                      }
                      reader.readAsDataURL(e.target.files[0]);
                  }
                  
                  // Edit for multiple images
                  // I didn't try but it should work.
                  // Also you need write some CSS code to see all images in container properly.
                  function handleImages(e) {
                      $('.uploader img').remove();
                      for(var i = 0; i < e.target.files.length; i++){
                          var reader = new FileReader();
                          reader.onload = function (event) {
                              var $img = $('<img/>');
                              $img.attr('src', event.target.result);
                              $('.uploader').append($img);
                          }
                          reader.readAsDataURL(e.target.files[i]);
                      }
                  }
                  

                  html

                  <div class="uploader" onclick="$('#filePhoto').click()">
                      click here or drag here your images for preview and set userprofile_picture data
                      <img src=""/>
                      <input type="file" name="userprofile_picture"  id="filePhoto" />
                  </div>
                  

                  我希望它有所帮助.可以查看http://jsfiddle.net/ELcf6/4/等版本http://jsfiddle.net/ELcf6/8/

                  i hope it helps. You can check http://jsfiddle.net/ELcf6/4/, and other version http://jsfiddle.net/ELcf6/8/

                  这篇关于上传前拖放图像输入文件和预览的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:将大文件切成块并使用 ajax 和 html5 FileReader 上传 下一篇:Dropzone.js 用 php 删除按钮

                  相关文章

                      <bdo id='ZLuMI'></bdo><ul id='ZLuMI'></ul>
                    <tfoot id='ZLuMI'></tfoot>

                    <legend id='ZLuMI'><style id='ZLuMI'><dir id='ZLuMI'><q id='ZLuMI'></q></dir></style></legend>

                    <i id='ZLuMI'><tr id='ZLuMI'><dt id='ZLuMI'><q id='ZLuMI'><span id='ZLuMI'><b id='ZLuMI'><form id='ZLuMI'><ins id='ZLuMI'></ins><ul id='ZLuMI'></ul><sub id='ZLuMI'></sub></form><legend id='ZLuMI'></legend><bdo id='ZLuMI'><pre id='ZLuMI'><center id='ZLuMI'></center></pre></bdo></b><th id='ZLuMI'></th></span></q></dt></tr></i><div id='ZLuMI'><tfoot id='ZLuMI'></tfoot><dl id='ZLuMI'><fieldset id='ZLuMI'></fieldset></dl></div>

                    <small id='ZLuMI'></small><noframes id='ZLuMI'>