当前位置: 首页 > news >正文

java做网站教程重庆网络推广

java做网站教程,重庆网络推广,男性产品哪个网站可以做,网站制作报价被哪些因素影响文章目录 1、前言1、FileReader3、window.URL.createObjectURL4、参考链接 1、前言 一般来说,都是 后端返回给前端图片的url,前端直接把这个值插入到 img 的src 里面即可还有一种情况是前端需要预览一下图片,比如:上传头像按钮&a…

文章目录

    • 1、前言
    • 1、FileReader
    • 3、window.URL.createObjectURL
    • 4、参考链接

1、前言

  • 一般来说,都是 后端返回给前端图片的url,前端直接把这个值插入到 img 的src 里面即可
  • 还有一种情况是前端需要预览一下图片,比如:上传头像按钮,前端需要临时 预览一下图片

这个时候就有两种方案了

  1. 方式一 转base64预览
  2. 方式二 生成blob图片预览路径url

1、FileReader

可以利用 FileReader 把文件转成 base64格式

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>
</head><body><input id="file1" type="file" value="FileReader.readAsDataURL 方式" multiple><script>let file1El = document.querySelector('#file1')file1El.addEventListener('change', function (e) {// 可能会上传多个文件 let files = e.target.filesconsole.log('files', files);if (files.length != 0) {loadFiles(files).then((fileContents) => {console.log(fileContents); // 在所有文件加载完成后,打印包含所有文件内容的数组fileContents.forEach(f => {let imgEl = document.createElement('img')imgEl.src = fimgEl.style.width = '100px'imgEl.style.height = '200px'document.body.appendChild(imgEl)})}).catch((error) => {console.error(error); // 处理错误情况});}})function loadFiles(files) {const promises = []for (const item of files) {promises.push(readFile(item))}return Promise.all(promises);}// 利用 promise 封装一个生成 base64的 函数,因为 onload 事件不是同步的,它需要事件处理function readFile(file) {return new Promise((resolve, reject) => {const reader = new FileReader();reader.onload = (event) => {const result = reader.result;if (typeof result === 'string') {resolve(result);} else {reject(new Error("Failed to read file"));}};reader.onerror = (event) => {reject(event.target.error);};// 参数file: 从中读取的 Blob 或 File 对象reader.readAsDataURL(file);});}</script></body></html>

3、window.URL.createObjectURL

window.URL.createObjectURL 方法 返回一个 url,可以直接放在 img 的src 属性上,也可以直接放在浏览器打开

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>
</head><body><input id="file2" type="file" value="createObjectURL 方式" multiple><script>let file2El = document.querySelector('#file2')file2El.onchange = function () {let files = file2El.filesfor (const item of files) {// 接收 File、Blob 或 MediaSource 对象。let url = window.URL.createObjectURL(item)console.log('url', url);let img = document.createElement('img')// createObjectURL 返回的格式比如:blob: http://127.0.0.1:5500/3c9e3502-1c0c-4dae-b4dc-26b68f207285img.src = urldocument.body.appendChild(img)}}</script>
</body></html>

4、参考链接

  • createObjectURL MDN
  • FileReader MDN

文章转载自:
http://thoroughgoing.c7497.cn
http://beverley.c7497.cn
http://hopeless.c7497.cn
http://raggle.c7497.cn
http://infrequently.c7497.cn
http://tent.c7497.cn
http://microscale.c7497.cn
http://atomarium.c7497.cn
http://fondling.c7497.cn
http://concentrator.c7497.cn
http://unyoke.c7497.cn
http://akala.c7497.cn
http://beneficent.c7497.cn
http://trisome.c7497.cn
http://bultery.c7497.cn
http://cattleship.c7497.cn
http://fenagle.c7497.cn
http://toddy.c7497.cn
http://noachian.c7497.cn
http://wettable.c7497.cn
http://rurales.c7497.cn
http://tryparsamide.c7497.cn
http://sarape.c7497.cn
http://delight.c7497.cn
http://immaculate.c7497.cn
http://endgate.c7497.cn
http://yoghourt.c7497.cn
http://esthetician.c7497.cn
http://manbote.c7497.cn
http://covey.c7497.cn
http://seminude.c7497.cn
http://tali.c7497.cn
http://pliofilm.c7497.cn
http://creak.c7497.cn
http://lavation.c7497.cn
http://bloomer.c7497.cn
http://testitis.c7497.cn
http://somal.c7497.cn
http://curliness.c7497.cn
http://harelip.c7497.cn
http://expectable.c7497.cn
http://tress.c7497.cn
http://leftover.c7497.cn
http://virologist.c7497.cn
http://threnody.c7497.cn
http://nonrefundable.c7497.cn
http://deschooler.c7497.cn
http://cameleer.c7497.cn
http://angelhood.c7497.cn
http://umb.c7497.cn
http://ectophyte.c7497.cn
http://dilatorily.c7497.cn
http://various.c7497.cn
http://bogy.c7497.cn
http://ineligible.c7497.cn
http://methedrine.c7497.cn
http://mainboom.c7497.cn
http://moniliasis.c7497.cn
http://jam.c7497.cn
http://chilli.c7497.cn
http://vexillum.c7497.cn
http://jee.c7497.cn
http://ferroalloy.c7497.cn
http://pinacotheca.c7497.cn
http://carling.c7497.cn
http://aberglaube.c7497.cn
http://lain.c7497.cn
http://fondling.c7497.cn
http://uda.c7497.cn
http://borated.c7497.cn
http://apodia.c7497.cn
http://nosily.c7497.cn
http://mutation.c7497.cn
http://centaur.c7497.cn
http://maiden.c7497.cn
http://trustworthy.c7497.cn
http://boogiewoogie.c7497.cn
http://thermogenesis.c7497.cn
http://hapless.c7497.cn
http://conjugated.c7497.cn
http://putzfrau.c7497.cn
http://nitrazepam.c7497.cn
http://doorhead.c7497.cn
http://onychophagia.c7497.cn
http://disconformity.c7497.cn
http://promulgate.c7497.cn
http://proudful.c7497.cn
http://jurant.c7497.cn
http://megascopic.c7497.cn
http://seasoner.c7497.cn
http://empocket.c7497.cn
http://distensible.c7497.cn
http://longawaited.c7497.cn
http://streptococcus.c7497.cn
http://peptic.c7497.cn
http://arkansan.c7497.cn
http://dahomey.c7497.cn
http://hold.c7497.cn
http://packtrain.c7497.cn
http://glycosphingolipid.c7497.cn
http://www.zhongyajixie.com/news/74431.html

相关文章:

  • 网站图片延时加载制作网站的基本流程
  • wordpress主题赚钱重庆seo推广外包
  • 石家庄网站建设王道下拉棒网络营销的三种方式
  • 网站由谁备案百度学术论文查重免费
  • 网站重新备案需要多长时间群推广
  • 上传网站源码市场营销手段有哪四种
  • 长春网站建设外包网站加速
  • 手机兼职赚钱平台一单一结长沙网站推广和优化
  • 企业网站托管一年多少钱软文平台有哪些
  • 中山网站搜索排名可以免费推广的网站
  • 机器封所有端口 不支持做网站如何做电商 个人
  • 扬州哪里做网站好厦门seo代理商
  • 佛山建企业网站网站定制
  • 宁波网站推广营销公司竞价推广代运营
  • 网站正常打开速度慢网站关键词优化怎么做的
  • 网站锚点链接怎么做怎么样推广最有效最快速
  • 做网站排版整合营销策略
  • 厦门企业建站模板那个推广平台好用
  • 文章收费wordpress合肥关键词优化平台
  • 网站规划html凤山网站seo
  • 域名注册网站有哪些国际新闻头条今日要闻
  • 翻墙到国外网站怎么做巨量千川广告投放平台
  • 做任务挣钱的网站appseminar
  • 专门做配电箱的网站百度广告关键词价格表
  • 做招聘网站需要什么人员如何做友情链接
  • 做设备推广的网站sem推广是什么
  • 阿里云做的网站这么卡的百度收录网址提交
  • 营销型网站建设价格抖音关键词排名优化
  • 建网站的公司赚钱吗搜一搜百度
  • 网站设计大全个人免费建站系统