zoukankan      html  css  js  c++  java
  • 上传图片预览

     1//多张图片上传前预览 

    function previewFiles() { 2 var preview = document.querySelector('#box'); 3 var files = document.querySelector('input[type=file]').files 4 function readAndPreview(file) { 5 6 // Make sure `file.name` matches our extensions criteria 7 if ( /.(jpe?g|png|gif)$/i.test(file.name) ) { 8 var reader = new FileReader(); 9 10 reader.addEventListener("load", function () { 11 var image = new Image(); 12 image.src = this.result; 13 image.height=85; 14 image.width=85; 15 image.margin=5; 16 image.border= "1px solid #ccc" 17 preview.appendChild( image ); 18 }, false); 19 reader.readAsDataURL(file); 20 } 21 } 22 if (files) { 23 [].forEach.call(files, readAndPreview); 24 } 25 26 }
    Solve problems in the most elegant way
  • 相关阅读:
    笔记
    创建和使用URL访问网上资源
    File
    event_1:事件注册
    3_3:创建 元素节点
    动态创建表格
    留言删除案例
    3_2:操作节点 [ 增 删 复制 ]
    5:to do list
    仿新浪下拉菜单
  • 原文地址:https://www.cnblogs.com/yanghmartin/p/upload_img.html
Copyright © 2011-2022 走看看