zoukankan      html  css  js  c++  java
  • 网页是如何实现从剪贴板从读取图片并上传到server的

    代码比较简单,原理更简单,不多言请直接看代码。

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <script src="https://code.jquery.com/jquery-2.1.4.min.js"></script> </head> <body> <script> document.onpaste = function(event){ var items = (event.clipboardData || event.originalEvent.clipboardData).items; for (var i = 0 ; i < items.length ; i++) { var item = items[i]; if (item.type.indexOf("image") != -1) { var file = item.getAsFile(); console.log(file); upload_file_with_ajax(file); } } } function upload_file_with_ajax(file){ var formData = new FormData(); formData.append('file', file); $.ajax('./clipboard_js.php' , { type: 'POST', contentType: false, processData: false, data: formData, error: function() { console.log("error"); }, success: function(res) { console.log("ok"); } }); } </script> </body> </html>
  • 相关阅读:
    针对性博文
    spring事务
    Redis_主从模式_哨兵模式_Cluster集群模式
    Redis AOF、RDB持久化
    Redis 高可用分布式集群
    Redis 基础
    Oracle优化学习
    Mysql:索引实战
    Mysql:性能优化
    js 二维数组定义
  • 原文地址:https://www.cnblogs.com/kevin7234/p/10617876.html
Copyright © 2011-2022 走看看