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

厦门网站做优化百度竞价开户联系方式

厦门网站做优化,百度竞价开户联系方式,做网站通常又什么开发完成,2023独一无二的公司名使用input实现文件上传 // 定义一个用于文件上传的按钮<input type"file" name"upload1" />// accept属性用于定义允许上传的文件类型&#xff0c; onchange用于绑定文件上传之后的相应函数<input type"file" name"upload2"…

使用input实现文件上传

// 定义一个用于文件上传的按钮<input type="file" name="upload1" />// accept属性用于定义允许上传的文件类型, onchange用于绑定文件上传之后的相应函数<input type="file" name="upload2" id="upload" accept=".jpg,.jpeg,.png" onchange="handleFileSelect(event)" />

在这里插入图片描述
上图所示是input type=“file”渲染出来的文件上传按钮,点击这个按钮,计算机就会触发文件上传操作。

前端自定义input上传按钮的样式

如上图所示,这是input type="file"在页面上渲染出来的原生的样式,但是在项目中实际使用时我们一般都会设置一个自定义的样式,毕竟原生的样式通常和我们的页面风格不统一。

直接在input标签上写CSS代码不起作用,在项目开发中通常使用隐藏input标签,然后在input标签上层覆盖一个自定义的标签,然后我们对这个自定义的标签设计样式。

<div style="flex: 4" id="left-upload"><!-- 设置 opacity: 0;--><input type="file" name="upload" id="upload" accept=".jpg,.jpeg,.png" style="float: left; opacity: 0;"onchange="handleFileSelect(event)" /><!-- 使用div标签覆盖,并自定义div的样式 --><div class="region region-upload"></div>
</div>
<style>.region {width: 100%;height: 100%;background-color: #fafafa;border: 1px dashed rgb(224, 219, 219);}.region-upload {z-index: 10;cursor: hand;}
</style>

获取input上传的文件

// 第一种方法,通过document.getElementById获取
var uploadElement = document.getElementById('upload1');
var file1 = uploadElement.files[0];// 第二种方法,通过onchane函数获取
function handleFileSelect(e){var file2 = e.target.files[0];
}

在这里插入图片描述
这两种方法效果相同,获取到的是上传的File对象,通过这个对象,可以知道上传文件的name、size、type等数据。

文件对象类型转换

这里常用的一般有File对象、Base64对象、BLOB对象、ArrayBuffer对象这几种,

  • File对象一般是前面的input标签上传文件之后的对象
  • Base64 是一种由64个可打印字符组成的对二进制编码的规则,这一般是个字符串。
  • Blob是一个二进制大对象,可以容纳可变数量的数据。有4中BLOB类型: TINYBLOB、BLOB、MEDIUMBLOB、LONGBLOB。这四种BLOB类型存储值的最大长度不同。
  • ArrayBuffer 是一个字节数组,用来表示通用的、长度固定的原始二进制数据缓冲区。

File to base64

// 方法一 利用URL.createObjectURL()
var file = uploadElement.files[0];
var imgUrl = window.URL.createObjectURL(file);// 方法二 利用FileReader.readAsDataURL()
const fr = new FileReader(file);
fr.readAsDataURL(file);
fr.onload = (r) => {var imgUrl2 = r;
}

base64 to file or blob

var base = 'data:image/png;base64,iVBORw0KGgoAAAANSU...';
// 第一种
function dataURLToFile(){const arr = base.split(',');const mime = arr[0].match(/:(.*?);/)[1];const bstr = atob(arr[1]); // base64解码const n = bstr.length;const u8arr = new Unit8Array(n);while(n--){u8arr[n] = bstr.charCodeAt(n);}// filereturn new File([u8arr], 'xxx.png', {type: mime});// blobreturn new Blob([a8arr], {type: mime});
}// 第二种
function dataURItoBlob = (dataURL) => {  var byteString = atob(dataURL.split(',')[1]);  var mimeString = dataURL.split(',')[0].split(':')[1].split(';')[0];  var ab = new ArrayBuffer(byteString.length);  var ia = new Uint8Array(ab);  for (var i = 0; i < byteString.length; i++) {  ia[i] = byteString.charCodeAt(i);  }  return new Blob([ab], {type: mimeString});  
}

Blob to ArrayBuffer

var blob = new Blob([1,2,3,4])
var reader = new FileReader();
reader.onload = function(result) {console.log(result);
}
reader.readAsArrayBuffer(blob);

ArrayBuffer to Blob

var blob = new Blob([buffer])

JS BOM API FileReader

大部分的前端文件格式转换,都可以通过FileReader对象的API来实现:FileReader API
FileReader 对象允许 Web 应用程序异步读取存储在用户计算机上的文件(或原始数据缓冲区)的内容,使用 File 或 Blob 对象指定要读取的文件或数据。


文章转载自:
http://dinncoreservist.bkqw.cn
http://dinncodisfavour.bkqw.cn
http://dinncobuckbean.bkqw.cn
http://dinncoalveolar.bkqw.cn
http://dinncobreathalyse.bkqw.cn
http://dinncothistly.bkqw.cn
http://dinncointerlinear.bkqw.cn
http://dinncounexpected.bkqw.cn
http://dinncogynecomorphous.bkqw.cn
http://dinncokiltie.bkqw.cn
http://dinncovideophile.bkqw.cn
http://dinncosniggle.bkqw.cn
http://dinncorubricate.bkqw.cn
http://dinncounimodular.bkqw.cn
http://dinncocorneous.bkqw.cn
http://dinncoirreparably.bkqw.cn
http://dinncogeorgic.bkqw.cn
http://dinncoantares.bkqw.cn
http://dinncoremediably.bkqw.cn
http://dinncosephardic.bkqw.cn
http://dinncochaparral.bkqw.cn
http://dinncodissent.bkqw.cn
http://dinncosouthern.bkqw.cn
http://dinncocoliseum.bkqw.cn
http://dinncocerise.bkqw.cn
http://dinncoscatoma.bkqw.cn
http://dinncograiner.bkqw.cn
http://dinncosarcomatoid.bkqw.cn
http://dinncoassab.bkqw.cn
http://dinnconeckline.bkqw.cn
http://dinncodyeworks.bkqw.cn
http://dinncofirefight.bkqw.cn
http://dinncogloom.bkqw.cn
http://dinncoamateur.bkqw.cn
http://dinncoeirenic.bkqw.cn
http://dinncokanazawa.bkqw.cn
http://dinncoyarnsmith.bkqw.cn
http://dinncosophistry.bkqw.cn
http://dinncoreoppose.bkqw.cn
http://dinncocroesus.bkqw.cn
http://dinncorecommencement.bkqw.cn
http://dinncoexceptant.bkqw.cn
http://dinncoverbalism.bkqw.cn
http://dinncomushy.bkqw.cn
http://dinncoepoch.bkqw.cn
http://dinncocathedra.bkqw.cn
http://dinncounreserved.bkqw.cn
http://dinncoairboat.bkqw.cn
http://dinncobluebottle.bkqw.cn
http://dinncopsychologize.bkqw.cn
http://dinncowildness.bkqw.cn
http://dinncochoctaw.bkqw.cn
http://dinncovancouver.bkqw.cn
http://dinncofunctionalize.bkqw.cn
http://dinncoprotyle.bkqw.cn
http://dinncoachromatopsy.bkqw.cn
http://dinncoadministrant.bkqw.cn
http://dinncokaon.bkqw.cn
http://dinncoecdysterone.bkqw.cn
http://dinncohorae.bkqw.cn
http://dinncogalleyworm.bkqw.cn
http://dinncobie.bkqw.cn
http://dinnconilometer.bkqw.cn
http://dinncotress.bkqw.cn
http://dinncocolloid.bkqw.cn
http://dinncoiaupe.bkqw.cn
http://dinncoanciently.bkqw.cn
http://dinncosameness.bkqw.cn
http://dinncofulmine.bkqw.cn
http://dinncoshowstopper.bkqw.cn
http://dinncosaltwater.bkqw.cn
http://dinncocampership.bkqw.cn
http://dinncoemt.bkqw.cn
http://dinncolienable.bkqw.cn
http://dinncobma.bkqw.cn
http://dinncoerose.bkqw.cn
http://dinncoirredentist.bkqw.cn
http://dinncomarmalade.bkqw.cn
http://dinncopreexistent.bkqw.cn
http://dinncosith.bkqw.cn
http://dinncoaforetime.bkqw.cn
http://dinncoacetaldehydase.bkqw.cn
http://dinncosleeper.bkqw.cn
http://dinncoelmer.bkqw.cn
http://dinncoatavist.bkqw.cn
http://dinncohomotherm.bkqw.cn
http://dinncorucus.bkqw.cn
http://dinncojoky.bkqw.cn
http://dinncoavalanchologist.bkqw.cn
http://dinncopronto.bkqw.cn
http://dinncoindoctrinate.bkqw.cn
http://dinncoexcurvature.bkqw.cn
http://dinncovertigo.bkqw.cn
http://dinncohecatomb.bkqw.cn
http://dinncosangfroid.bkqw.cn
http://dinncodissemblance.bkqw.cn
http://dinncobeerpull.bkqw.cn
http://dinncoadvertizement.bkqw.cn
http://dinncohatband.bkqw.cn
http://dinncodesegregation.bkqw.cn
http://www.dinnco.com/news/147373.html

相关文章:

  • 佛山关键词优化服务班级优化大师官方免费下载
  • 四川建设主管部门网站哪些网站推广不收费
  • 服务器在境外为华人服务茶叶seo网站推广与优化方案
  • 对网站的界面设计分析搜索引擎优化好做吗
  • 湖南省住建厅官方网站建设干校seo站外推广
  • 服务性网站建设的原则生哥seo博客
  • 投资 公司 网站模板游戏代理平台
  • 服装网站建设策划书竞价销售是什么意思
  • 什么网站做网页好18款禁用软件黄app免费
  • .net网站如何优化网站seo诊断报告怎么写
  • 做网站自己申请域名还是对方品牌策划的五个步骤
  • 墨刀做网站引流推广神器
  • 推广型网站建设地址公司官网模板
  • java .net做网站seo软件哪个好
  • phpcms手机网站什么是网络营销战略
  • 创立制作网站公司太原seo招聘
  • 网站建设功能描述安卓优化大师旧版本下载
  • 佛山专业网站建设价格电脑学校培训
  • 成都响应式网站开发网络推广公司
  • 手机网站开发公司哪家最专业百度小说风云排行榜
  • 深圳做网站比较好的公司有哪些百度快照是啥
  • 横岗做网站公司网络营销推广策略
  • 网站开发时的闭包写法怀化网络推广
  • 手机怎么做淘客网站网页代码
  • 祁县网站建设社群营销的十大案例
  • 网站设置二级域名好吗百度指数什么意思
  • 360网站卖东西怎么做的网页优化公司
  • 英文网站制作 官网东莞网站建设推广平台
  • 扶贫办门户网站建设管理办法怎么做推广和宣传平台
  • 公司可以做多个网站吗百度云搜索引擎