当前位置:网站首页>文件的下载与图片的预览
文件的下载与图片的预览
2022-07-02 09:46:00 【1900's 88 keys】
文件的下载
a标签指定了download属性时会下载跳转的链接,前提是同源
<h2>前端的blob对象 --- 文件的下载 && 图片的预览</h2>
<br>
<a id="btn">下载文件</a>
<script> var str = ` <div> <p>文件的下载</> </div> `; var blob = new Blob([str], {
type: 'text/html' }); btn.onclick = function (e) {
this.setAttribute('download', '123.html'); this.href = URL.createObjectURL(blob); } </script>
图片的预览
<input type="file" id="input1">
<input type="file" id="input2">
<script> // 同步 input1.onchange = function (e) {
var file = e.target.files[0]; var img = new Image(); img.src = URL.createObjectURL(file) document.body.appendChild(img) } // 异步 input2.onchange = function (e) {
var file = e.target.files[0]; var img = new Image(); var fileRead = new FileReader(); document.body.appendChild(img) fileRead.onload = function () {
img.src = fileRead.result } fileRead.readAsDataURL(file) } </script>
边栏推荐
- JDBC prevent SQL injection problems and solutions [preparedstatement]
- OLED screen driver based on stm32
- Interval DP acwing 282 Stone merging
- 日本赌国运:Web3.0 ,反正也不是第一次失败了!
- 屠榜多目标跟踪!BoT-SORT:稳健的关联多行人跟踪
- 上手报告|今天聊聊腾讯目前在用的微服务架构
- Get started REPORT | today, talk about the microservice architecture currently used by Tencent
- Hash table acwing 840 Simulated hash table
- Js5day (event monitoring, function assignment to variables, callback function, environment object this, select all, invert selection cases, tab column cases)
- JS generates 4-digit verification code
猜你喜欢
Js4day (DOM start: get DOM element content, modify element style, modify form element attributes, setinterval timer, carousel Map Case)
阿里初面被两道编程题给干掉,再次内推终上岸(已拿电子offer)
net share
(6) Web security | penetration test | network security encryption and decryption ciphertext related features, with super encryption and decryption software
Analog to digital converter (ADC) ade7913ariz is specially designed for three-phase energy metering applications
js1day(输入输出语法,数据类型,数据类型转换,var和let区别)
Unity SKFramework框架(二十)、VFX Lab 特效库
VIM super practical guide collection of this one is enough
Hash table acwing 841 String hash
Dijkstra AcWing 850. Dijkstra finding the shortest circuit II
随机推荐
spfa AcWing 851. SPFA finding the shortest path
Heap acwing 838 Heap sort
Js6day (search, add and delete DOM nodes. Instantiation time, timestamp, timestamp cases, redrawing and reflow)
基于STM32的OLED 屏幕驱动
PXE installation UOS prompt NFS over TCP not available from 10 x.x.x
[opencv learning] [Canny edge detection]
架构师必须了解的 5 种最佳软件架构模式
Fully autonomous and controllable 3D cloud CAD: crowncad's convenient command search can quickly locate the specific location of the required command.
Jerry's watch modifies the alarm clock [chapter]
js4day(DOM开始:获取DOM元素内容,修改元素样式,修改表单元素属性,setInterval定时器,轮播图案例)
Unity skframework framework (XIV), extension extension function
(7) Web security | penetration testing | how does network security determine whether CND exists, and how to bypass CND to find the real IP
自主可控三维云CAD:CrownCAD赋能企业创新设计
Structured data, semi-structured data and unstructured data
How can attribute mapping of entity classes be without it?
Browser storage scheme
Async/await asynchronous function
Unity skframework Framework (XVI), package manager Development Kit Manager
Unity SKFramework框架(十二)、Score 计分模块
js1day(輸入輸出語法,數據類型,數據類型轉換,var和let區別)