博客
关于我
原生js之图片预览的封装
阅读量:201 次
发布时间:2019-02-28

本文共 682 字,大约阅读时间需要 2 分钟。

图片预览

_this:input[file]对象

_thisNext:下一个要操作的DOM对象

cb:回调函数

                    function changeImg(_this, _thisNext, cb) {                var reader = new FileReader();                reader.readAsDataURL(_this.files[0]);                reader.onload = function(e) {                    _this.nextSibling.src = e.target.result;                    if (cb) {                        cb(_thisNext);                    }                };            }            

技术说明:

  • 该函数通过DOM事件处理,实现文件读取与图片展示功能
  • 函数参数包括当前文件输入框对象(_this)、下一个需要操作的DOM对象(_thisNext)以及回调函数(cb)
  • 当文件读取完成后,会自动设置下一个DOM对象的src属性
  • 支持回调函数的调用,允许外部定义具体操作逻辑

转载地址:http://lohi.baihongyu.com/

你可能感兴趣的文章
Nmap端口扫描工具Windows安装和命令大全(非常详细)零基础入门到精通,收藏这篇就够了
查看>>
NMAP网络扫描工具的安装与使用
查看>>
NN&DL4.1 Deep L-layer neural network简介
查看>>
NN&DL4.3 Getting your matrix dimensions right
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>
No qualifying bean of type XXX found for dependency XXX.
查看>>
No resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>
No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
查看>>
NO.23 ZenTaoPHP目录结构
查看>>
NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata
查看>>
Node JS: < 一> 初识Node JS
查看>>