Home >Web Front-end >JS Tutorial >Detailed explanation of the steps to implement file drag and drop using JS

Detailed explanation of the steps to implement file drag and drop using JS

php中世界最好的语言
php中世界最好的语言Original
2018-04-27 16:45:261868browse

This time I will bring you a detailed explanation of the steps to implement file dragging with JS. What are the precautions for implementing file dragging with JS. The following is a practical case, let’s take a look.

The example in this article shares with you javascript the specific code to implement the file drag and drop event 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>

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Detailed explanation of Element Traversal implementation of element traversal

Detailed explanation of the use of api interface in vue project

The above is the detailed content of Detailed explanation of the steps to implement file drag and drop using JS. 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