Skip to content

[js] 第411天 写一个方法粘贴复制的图片并显示出来 #2450

Open
@haizhilin2013

Description

@haizhilin2013
Collaborator

第411天 写一个方法粘贴复制的图片并显示出来

3+1官网

我也要出题

Activity

xiaoqiangz

xiaoqiangz commented on May 6, 2023

@xiaoqiangz

主要是监听paste事件,并使用event.ClipboardEvent来处理。
document.body.addEventListener('paste', function (event) {
var items = event.clipboardData.items;
if (items && (items[0].type.indexOf('image') > -1 )) {
var file = null // 用于存储图片文件
file = items[0].getAsFile();
// 直接显示到当前页面
document.querySelector('#myimg').src = URL.createObjectURL(file)
}
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    jsJavaScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @haizhilin2013@xiaoqiangz

        Issue actions

          [js] 第411天 写一个方法粘贴复制的图片并显示出来 · Issue #2450 · haizlin/fe-interview