Javascript 类的多个事件侦听器

Javascript 类的多个事件侦听器,javascript,jquery,drag-and-drop,event-listener,Javascript,Jquery,Drag And Drop,Event Listener,我正在尝试创建多个拖放区域。我正在尝试为一个“drop zone”类添加侦听器(用于该类的每个元素) 您需要查询具有特定类的所有元素 // Returns a list of the elements within the document // that match the specified 'drop-zone' class. var dropZones = document.querySelectorAll('.drop-zone'); for (var i = 0; i &

我正在尝试创建多个拖放区域。我正在尝试为一个“drop zone”类添加侦听器(用于该类的每个元素)


您需要查询具有特定类的所有元素

// Returns a list of the elements within the document 
// that match the specified 'drop-zone' class.   
var dropZones = document.querySelectorAll('.drop-zone');


for (var i = 0; i < dropZones.length; i++) {
  // Add the event listeners for each element of the list.
  dropZones[i].addEventListener('dragover', function (e) {
    // ...
  });

 dropZones[i].addEventListener('drop', function (e) {
   // ...
 });
}
//返回文档中元素的列表
//与指定的“放置区域”类匹配的。
var dropZones=document.querySelectorAll('.dropzone');
对于(var i=0;i
您需要查询具有特定类的所有元素

// Returns a list of the elements within the document 
// that match the specified 'drop-zone' class.   
var dropZones = document.querySelectorAll('.drop-zone');


for (var i = 0; i < dropZones.length; i++) {
  // Add the event listeners for each element of the list.
  dropZones[i].addEventListener('dragover', function (e) {
    // ...
  });

 dropZones[i].addEventListener('drop', function (e) {
   // ...
 });
}
//返回文档中元素的列表
//与指定的“放置区域”类匹配的。
var dropZones=document.querySelectorAll('.dropzone');
对于(var i=0;i