Home  >  Article  >  Web Front-end  >  Javascript implements file drag and drop event

Javascript implements file drag and drop event

亚连
亚连Original
2018-05-28 13:43:371497browse

This article mainly introduces the implementation of file drag and drop events in javascript in detail. It has certain reference value. Interested friends can refer to it.

The example in this article shares with everyone the implementation of file drag and drop in javascript. The specific code of the drag event is for your reference. The specific content is as follows

1. Rendering:

2. Source code

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
  <style type="text/css">
    #p1 {
      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>

<p id="p1" ondrop="drop(event)" ondragover="allowDrop(event)">将文件拖放到此处</p>

</body>
</html>

above I compiled it for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Vue-cli development environment method to implement cross-domain requests

Detailed explanation of Vue-cli webpack mobile terminal automated construction rem problem

Native nodejs uses websocket code sharing

The above is the detailed content of Javascript implements file drag and drop event. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to use swiper in vueNext article:How to use swiper in vue