如何给html中的input赋值一个文件 您所在的位置:网站首页 如何给input赋值 如何给html中的input赋值一个文件

如何给html中的input赋值一个文件

2023-05-16 01:15| 来源: 网络整理| 查看: 265

我有一个html文件中有一个dropbox和一个input,对应的有一个js控制dropbox中的onchange,我现在需要已经能够拖拽上传图片了,但是上传的图片内容在dropbox里面,可以用alert读出来图片名字,大小等信息,这个文件叫file。但是不知道怎么把这个文件赋值给input,因为上传的功能是绑定在input上的。困扰很久了QAQ

请拖拽上传图片~~ function processFiles(files) { var file = files[0]; alert(file.value) alert(file.name) alert(file.size) input.value=file.value var output = document.getElementById("fileOutput"); //创建FileReader var reader = new FileReader(); //告诉它在准备好数据之后做什么 reader.onload = function (e) { //使用图像URL来绘制dropBox的背景 dropBox.style.backgroundImage = "url('" + e.target.result + "')"; dropBox.style.backgroundSize = "contain"; document.getElementById("dropBox").value=""; // var img_value = document.getElementById("dropBox"); }; //读取图片 reader.readAsDataURL(file); }


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有