<label for="file">
<img src="data:images/morende.jpg" alt="">
<span>点击更换头像</span>
</label>
<input type="file" name="file" id="file" accept="image/*" value="" hidden=""/>
$("input[type='file']").change( function(event) {//上传图片
  console.log(event)
var file = event.currentTarget.files[0]
var formFile = new FormData();
formFile.append("file", file); $.ajax({
url: ajaxURL+'/currency/istImage',
type: 'POST',
data: formFile,
async: true,
cache: false,
contentType: false,
processData: false,
dataType:'json',
success: function(res) {
console.log(res);
}
}) });

或者循环多个上传

<input type="file" onchange="upload(this)">
<script>
function upload(obj){
var files = obj.files ;
var formData = new FormData();
for(var i = 0;i<files.length;i++){
formData.append("upfile[]", files[i]); }
$.ajax({
url: "1.php",
type: "POST",
data:formData,
cache:false, //不设置缓存
processData: false, // 不处理数据
contentType: false // 不设置内容类型
});
}
</script>

input type=file实现图片上传的更多相关文章

  1. input type=file实现图片上传,预览以及图片删除

    背景 前两天在做一个PC网站的意见反馈,其中涉及到了图片上传功能,要求可以上传多张图片,并且支持图片上传预览及图片删除, 图片上传这一块以前没怎么搞过,而且一般也很少会碰到这样的需求,所以在做这个功能 ...

  2. input type="file"多图片上传 原生html传递的数组集合

    单个的input type="file"表单也是可以实现多图片上传的 代码如下: <form action="manypic.php" method=&q ...

  3. input type="file"多图片上传

    单个的input type="file"表单也是可以实现多图片上传的 代码如下: <form action="manypic.php" method=&q ...

  4. jquery的input:type=file实现文件上传

    <!DOCTYPE html> <html> <head> <title>html5_2.html</title> <style> ...

  5. input type="file" accept="image/*"上传文件慢的问题解决办法

    相信大家都写过<input type="file" name="file" class="element" accept=" ...

  6. input type=file 选择图片并且实现预览效果的实例

    为大家带来一篇input type=file 选择图片并且实现预览效果的实例. 通过<input />标签,给它指定type类型为file,可提供文件上传: accept:可选择上传类型, ...

  7. input type=file 选择图片并且实现预览效果

    通过<input />标签,给它指定type类型为file,可提供文件上传: accept:可选择上传类型,如:只要传图片,且不限制图片格式,为image/*: multiple:规定是否 ...

  8. html之file标签 --- 图片上传前预览 -- FileReader

    记得以前做网站时,曾经需要实现一个图片上传到服务器前,先预览的功能.当时用html的<input type="file"/>标签一直实现不了,最后舍弃了这个标签,使用了 ...

  9. 简单的html5 File base64 图片上传

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

随机推荐

  1. Spring Security 解析(四) ——短信登录开发

    Spring Security 解析(四) -- 短信登录开发   在学习Spring Cloud 时,遇到了授权服务oauth 相关内容时,总是一知半解,因此决定先把Spring Security ...

  2. keil 编译器V6 定义函数在ram中运行-和在指定地址定义常量

    之前一直是用v5编译,编译速度慢,换成V6编译速度差不多快50% ,而且arm后期只维护v5编译器不在更新v5编译器.切换到V6编译器大势所趋,把之前v5且换到v6需要如下更改: 1. CMSIS包需 ...

  3. C语言知识点总结篇

    Debug和Release版本比较 Debug附加了许多调试信息,主要用于调试,故文件大: Release是经过优化后的版本,去掉了调试信息,代码进行了优化,故文件较小,且编译速度快过Debug,用于 ...

  4. 一个 Java 正则表达式例子

    今天在项目里看到用 Python 正则表达式的时候,用到 group,没有仔细看.正好学习 Java 正则表达式,对 group 多留意了一下. 上代码: import java.util.regex ...

  5. win10下apache superset的使用

    官方文档:http://superset.apache.org/ 一.环境准备 安装python3即3.4以上版本 二.python创建一个虚拟环境用来作为superset的容器 -pip3 inst ...

  6. MOOC python笔记(二)python中的数据类型和基本语句

    python数据类型 数字类型 整数(int) 与数学中整数概念一致(数字大小没有限制,这和其他语言不同),整数可正可负,默认情况下,整数采用十进制.其他进制需要增加相应的引导符号. 如果是二进制在前 ...

  7. linux启动tomcat很久或者很慢Tomcat启动时卡在“INFO: Deploying web application directory ......”的解决方法

    解决方案: 找到jdk1.x.x_xx/jre/lib/security/java.security文件,在文件中找到securerandom.source这个设置项,将其改为: securerand ...

  8. Web api 右连接

    这是原来的代码,两个表的连接的方式是inner join ,查不出我要的全部数据. 后来把代码稍稍改一下,就是left join  join into 到一个临时对象里,相当于再select from ...

  9. javascript:void(0)的含义

    void关键字介绍 首先,void关键字是javascript当中非常重要的关键字,该操作符指定要计算或运行一个表达式,但是不返回值. 语法格式: void func() void(func()) 实 ...

  10. linux配置iptables

    iptables主要用来配置防火墙.其是一个需要特别谨慎设置的东西,服务器不在身边,不要贸然设置,有可能导致无法SSH,那就麻烦了. 1.首先介绍一下指令和相关配置文件 启动指令:service ip ...