当前位置:网站首页>文件的下载与图片的预览
文件的下载与图片的预览
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>
边栏推荐
- [200 opencv routines] 100 Adaptive local noise reduction filter
- Unity skframework Framework (XVI), package manager Development Kit Manager
- Hash table acwing 841 String hash
- 腾讯三面:进程写文件过程中,进程崩溃了,文件数据会丢吗?
- Unity SKFramework框架(十九)、POI 兴趣点/信息点
- Linear DP acwing 899 Edit distance
- Heap acwing 839 Simulated reactor
- Jerry's weather code table [chapter]
- Finally, someone explained the supervised learning clearly
- Browser storage scheme
猜你喜欢

js4day(DOM开始:获取DOM元素内容,修改元素样式,修改表单元素属性,setInterval定时器,轮播图案例)

Dijkstra AcWing 850. Dijkstra finding the shortest circuit II
![Jerry's watch ringtone audition [article]](/img/18/905c4b64443f4efca55188e36f4b28.jpg)
Jerry's watch ringtone audition [article]

Modular commonjs es module

Unity SKFramework框架(十六)、Package Manager 开发工具包管理器

Hash table acwing 840 Simulated hash table

C operator

Js3day (array operation, JS bubble sort, function, debug window, scope and scope chain, anonymous function, object, Math object)

Unity SKFramework框架(二十)、VFX Lab 特效库

Apply lnk306gn-tl converter, non isolated power supply
随机推荐
Linear DP acwing 899 Edit distance
Unity SKFramework框架(二十一)、Texture Filter 贴图资源筛选工具
C operator
Post order traversal sequence of 24 binary search tree of sword finger offer
Rust语言文档精简版(上)——cargo、输出、基础语法、数据类型、所有权、结构体、枚举和模式匹配
Day4 operator, self increasing, self decreasing, logical operator, bit operation, binary conversion decimal, ternary operator, package mechanism, document comment
获取文件版权信息
Package management tools
Unity skframework Framework (XVI), package manager Development Kit Manager
(7) Web security | penetration testing | how does network security determine whether CND exists, and how to bypass CND to find the real IP
嵌入式软件开发
OLED screen driver based on stm32
Js2day (also i++ and ++i, if statements, ternary operators, switch, while statements, for loop statements)
Domestic free data warehouse ETL dispatching automation operation and maintenance expert taskctl
net share
Word efficiency guide - word's own template
Ali on three sides, it's really difficult to successfully get the offer rated P7
Explain in detail the process of realizing Chinese text classification by CNN
West digital decided to raise the price of flash memory products immediately after the factory was polluted by materials
上海交大教授:何援军——包围盒(包容体/包围盒子)