2017-06-26 96 views
-1

我一直在努力將這些拖放到一個函數中,因此可以使用相同的類創建動態區域,從而允許我調用相同的函數進行上載。我的上傳功能工作正常。只需要弄清楚如何在一個函數中動態地創建這個函數。動態處理多個放置元素

<div id="dropZone1" class="dropZones" ></div> 
<div id="dropZone2" class="dropZones" ></div> 

    <script> 

     var dropMedical = document.getElementById('dropZone1'); 
     dropMedical.addEventListener('dragover', dragOver, false); 
     dropMedical.addEventListener('drop', fileSelect, false); 

     var dropStatements = document.getElementById('dropZone2'); 
     dropStatements.addEventListener('dragover', dragOver, false); 
     dropStatements.addEventListener('drop', fileSelect, false); 

    </script> 
+0

[請不要把問題標題標籤(https://stackoverflow.com/help/tagging) – Liam

+0

這個問題顯得缺乏實際問題(或任何問題分數?)? – Liam

回答

0

也許是這樣的?

dropZoneListener(zone) { 
 
    zone.addEventListener('dragover', dragOver, false); 
 
    zone.addEventListener('drop', fileSelect, false); 
 
} 
 

 
var dropMedical = document.getElementById('dropZone1'); 
 
dropZoneListener(dropMedical); 
 

 
var dropStatements = document.getElementById('dropZone2'); 
 
dropZoneListener(dropStatements);

+0

謝謝:::::: function dropZoneListener(zone){ zone.addEventListener('dragover',dragOver,false); zone.addEventListener('drop',fileSelect,false); ('.obj')。(函數(i,obj)){這個).attr('id'); zoneInput = $(this).find(「input」) .attr('id'); var dropped = document.getElementById(dropZone); dropZoneListener(dropped); }); – Kelly