<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>js粘贴</title> <meta http-equiv="content-type" content="text/html;charset=utf-8"> <style type="text/css"> .inp{ border: 1px solid #e5e5e5; height: 30px; line-height: 30px; margin: 30px; } </style> </head> <body> <input type="text" class="inp"> <script src="js/jq.js"></script> <script language="javascript"> $(function(){ $('.inp').get(0).addEventListener("paste", function (e) { if (!(e.clipboardData && e.clipboardData.items)) { return; } for (var i = 0, len = e.clipboardData.items.length; i < len; i++) { var item = e.clipboardData.items[i];//这个是一个对象 if (item.kind === "string") { item.getAsString(function (str) { console.log(str);//粘贴字符串的内容 }) } else if (item.kind === "file") { var f= item.getAsFile(); console.log(f);//文件 } } }); }) </script> </body> </html>