<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>表单提交</title>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
</head>
<body> <!--文件上传-->
<form id="uploadForm" enctype="multipart/form-data">
<div id="fileId" style='display: none'><!--//style='display: none'--> </div>
<div id="img-con" class="panel panel-default imgdiv"> </div>
<p id="em">未上传文件</p>
<input type="button" value="点击事件" name="点击事件" onclick="inputClieck()"><br>
<input type="submit">
</form>
</body>
<script> var inputArray = []; function inputClieck() {
var newInput = document.createElement("input");
newInput.type = 'file';
newInput.name = "files";
var idid = new Date().getTime();
newInput.id = idid;
$("#fileId").append(newInput);
inputArray.push(idid); $("#" + idid).click(); $("#" + idid).change(function (e) {
console.log('change事件', e);
console.log(this)
var path= getImgPath(this.files[0]);
console.log("--------"+path); var arr = path.split("/");
var strPath='--------:null/'+arr[arr.length-1];
console.log(strPath)
var a=createImg(path,idid);
$("#em").append(a) });
var newline = document.createElement("br");//创建一个BR标签是为能够换行!
$("#fileId").append(newline);
} //动态显示上传图片
function uploadImg(path) {
var imgDiv = $("#img-con");
var $img = $("<img/>");
$img.attr("src", path);
imgDiv.append($img);
} //获取要上传单张图片的本地路径
function getImgPath(file) { var url = null;
if(window.createObjectURL != undefined) { // basic
url = window.createObjectURL(file);
} else if(window.URL != undefined) { // mozilla(firefox)
url = window.URL.createObjectURL(file);
} else if(window.webkitURL != undefined) { // webkit or chrome
url = window.webkitURL.createObjectURL(file);
}
return url;
} function createImg(src,idid) {
var box = $("<div class='img-box uploadfile'>"); var newImg = document.createElement("img");
newImg.src=src;
newImg.id="img"+idid;
newImg.height=100;
newImg.width=100;
newImg.onclick='showImagePopup(\"" + src + "\")'; //box.append("<img src='" + src + "' height='100px' width='100px' onclick='showImagePopup(\"" + src + "\")'>");
box.append(newImg);
return box;
} function showImagePopup(src) {
if (getClass(src) === "String") {
var popup = $("<img></img");
popup.addClass("image-popup").attr("src", src);
var shade = $("<div></div>").addClass("shade");
$(document.body).append(shade.append(popup));
shade.click(function () {
$(this).remove();
});
popup.fadeIn(200);
// popup.click(function() {
// window.event ? window.event.cancelBubble = true :
// window.event.stopPropagation();
// });
}
} </script>
</html>

html多文件上传,可支持预览的更多相关文章

  1. dwz+jquery+fileupload+springmvc实现文件上传 及图片预览

    1 前台jsp:文件的上传利用了iframe实现局部刷新功能.使用了apache的fileupload组件,用到的jar: commons-fileupload.jar,commons-io.jarD ...

  2. php文件上传及头像预览

    php文件上传原理是通过form表单的enctype="multipart/form-data"属性将文件临时放到wamp文件夹中的tmp目录下,再通过后台php 程序将文件保存在 ...

  3. HTML5文件上传前本地预览

    HTML5之FileReader的使用 HTML5定义了FileReader作为文件API的重要成员用于读取文件,根据W3C的定义,FileReader接口提供了读取文件的方法和包含读取结果的事件模型 ...

  4. javascript实现文件上传之前的预览功能

    1.首先要给上传文件表单控件和图片控件设置name属性 <div class="form-group">                    <label fo ...

  5. jsp+springmvc实现文件上传、图片上传和及时预览图片

    1.多文件上传:http://blog.csdn.net/a1314517love/article/details/24183273 2.单文件上传的简单示例:http://blog.csdn.net ...

  6. Ajax上传图片以及上传之前先预览

    手头上有几个小项目用到了easyUI,一开始决定使用easyUI就注定了项目整体上前后端分离,基本上所有的请求都采用Ajax来完成.在文件上传的时候用到了Ajax上传文件,以及图片在上传之前的预览效果 ...

  7. java多图片上传--前端实现预览--图片压缩 、图片缩放,区域裁剪,水印,旋转,保持比例。

    java多图片上传--前端实现预览 前端代码: https://pan.baidu.com/s/1cqKbmjBSXOhFX4HR1XGkyQ 解压后: java后台: <!--文件上传--&g ...

  8. web 图片上传实现本地预览

    在说上传之前先说说如何替换or美化浏览器自带的简陋上传按钮(自定义自己的上传按钮 如:img): 1.将自定义上传按钮上方添加 input file 框,实现input实现透明处理. 2.对自定义上传 ...

  9. [.ashx檔?泛型处理例程?]基础入门#2....FileUpload上传前,预览图片(两种作法--ashx与JavaScript)

    原文出處  http://www.dotblogs.com.tw/mis2000lab/archive/2013/08/20/ashx_beginner_02_fileupload_picture_p ...

  10. 聊一聊jquery文件上传(支持多文件上传)

    谈到文件上传,现在一般都用现成的组件可以使用.PC端的可以使用uploadify.针对微网站H5也有uploadifive.但是这组件并不能满足各种场景的需求,例如:预览 切图 放大缩小,取消之类的. ...

随机推荐

  1. Linux报“ '/usr/bin' is not included in the PATH environment variable”解决方法

    https://www.cnblogs.com/alvinwei1024/p/4811993.html https://blog.csdn.net/drbinzhao/article/details/ ...

  2. Python默认参数的坑

    默认参数的坑 定义一个函数,传入一个list,添加一个end再返回 def add_end(L=[]): L.append('END') return L 正常调用时,结果似乎不错 print add ...

  3. laravel 在linux环境下解决.htaccess无效和去除index.php

    LoadModule rewrite_module modules/mod_rewrite.so (去掉前面的#注释) AllowOverride All (根目录的配置下,确保设置成All) < ...

  4. MTK 修改默认屏幕亮度

    frameworks\base\packages\SettingsProvider\res\values\defaults.xml <!-- Default screenbrightness, ...

  5. 【问题集】redis.clients.jedis.exceptions.JedisDataException: ERR value is not an integer or out of range

    redis.clients.jedis.exceptions.JedisDataException: ERR value is not an integer or out of range incrm ...

  6. 6.25html基础!

    <!DOCTYPE html> <html> <head> <title>form表单</title> </head> < ...

  7. case when then end

    当 a>b获取a,否则获取b,当a>c获取a,否则获取c,b大于c获取b否则获取c SELECT id,(CASE  WHEN a>b THEN a WHEN  a>c THE ...

  8. centos7 LANMP 安装

    没有开头语. 操作系统:CentOs7.6 64位. Nginx:系统自带 nginx1.12.2包. Mysql:系统自带 MariaDB 5.6 ,更换为 Mysql5.6 PHP:系统php5. ...

  9. 5:CSS元素类型

    5:CSS元素类型 学习目标 1.元素类型分类依据和元素类型分类 2.元素类型的转换 3.inline-block元素类型的应用 4.置换和非置换元素的概念和应用案例 一.元素类型分类依据和元素类型分 ...

  10. 逻辑卷管理LVM(logical volume manager)

    LVM的全名是logical volume manager,中文翻译逻辑卷管理器.之所以称为卷是因为可以将文件系统像卷一样伸长和缩短,LVM的做法是将几个物理的分区(或磁盘)通过软件组合成为一块独立的 ...