博客
关于我
原生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/

你可能感兴趣的文章
org.apache.poi.hssf.util.Region
查看>>
org.apache.xmlbeans.XmlOptions.setEntityExpansionLimit(I)Lorg/apache/xmlbeans/XmlOptions;
查看>>
org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /
查看>>
org.hibernate.HibernateException: Unable to get the default Bean Validation factory
查看>>
org.hibernate.ObjectNotFoundException: No row with the given identifier exists:
查看>>
SQL-CLR 类型映射 (LINQ to SQL)
查看>>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
查看>>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
查看>>
org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded
查看>>
org.tinygroup.serviceprocessor-服务处理器
查看>>
org/eclipse/jetty/server/Connector : Unsupported major.minor version 52.0
查看>>
org/hibernate/validator/internal/engine
查看>>
SQL-36 创建一个actor_name表,将actor表中的所有first_name以及last_name导入改表。
查看>>
ORM sqlachemy学习
查看>>
Ormlite数据库
查看>>
orm总结
查看>>
os.environ 没有设置环境变量
查看>>
os.path.join、dirname、splitext、split、makedirs、getcwd、listdir、sep等的用法
查看>>
os.system 在 Python 中不起作用
查看>>
OS2ATC2017:阿里研究员林昊畅谈操作系统创新与挑战
查看>>