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

<!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>

相关文章:

  • 2021-06-29
  • 2021-07-12
  • 2022-01-17
  • 2021-07-16
  • 2021-04-24
  • 2021-08-14
  • 2021-06-26
猜你喜欢
  • 2022-12-23
  • 2021-11-30
  • 2022-03-13
  • 2021-12-09
  • 2022-12-23
  • 2022-12-23
  • 2022-01-09
相关资源
相似解决方案