1.效果图:
2.源码
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <style type="text/css"> #div1 { width: 350px; height: 70px; padding: 10px; border: 1px solid #aaaaaa; text-align: center; } </style> <script type="text/javascript"> function allowDrop(ev) { ev.preventDefault(); } function drop(ev) { ev.preventDefault(); console.log(ev.dataTransfer.files); } </script> </head> <body> <div id="div1" ondrop="drop(event)" ondragover="allowDrop(event)">将文件拖放到此处</div> </body> </html>