Jestem całkiem nowy w jQuery i utknąłem próbując uzyskać identyfikator elementów przeciągniętych do dodania do celu upuszczenia zamiast samego elementu image lub id target drop. Używam natywnej wersji DnD HTML5. I do tej pory mogę pobrać sam element przez wysłanie przez jego id z metodą przesyłania danych w funkcji przeciągania i funkcji getdata w kropli. Ilekroć próbuję wywołać ten identyfikator z dropu, otrzymuje on identyfikator celu kropli zamiast przeciągniętych elementów.Wyświetlenie id upuszczonych elementów zamiast docelowego identyfikatora upuszczenia
Każda pomoc byłaby bardzo doceniana, ponieważ przeszukałem dokładnie online i znalazłem tylko kilka metod, aby uzyskać docelowy identyfikator obszaru upuszczenia. Oto fragment mojego obecnego kodu skrzypce:
function allowDrop(ev) {
ev.preventDefault();
}
function dragStart(ev) {
ev.dataTransfer.setData('Text/html', ev.target.id); // sends the dragged images data.
//alert(ev.target.id); // alerts the correct id of the dragged image.
}
function drop(ev) {
ev.preventDefault();
var data = ev.dataTransfer.getData("text/html");//retrieves dropped images data.
ev.target.appendChild(document.getElementById(data));//this displays the dropped image.
//alert(ev.target.id); // alerts the id of the drop target(Want to get the dropped images id.)
//$("#mybillets").append("<span>"+ev.target.id+" </span>"); //appends the drop targets id(Want to append the dropped images id.)
}
Jeśli masz element DOM w zmiennej o nazwie 'elem', to id jest po prostu' elem.id'. – jfriend00
w takim przypadku 'dane' powinny dać ci –
Jakieś rady, jak mogę to zaimplementować? Próbowałem tak wielu różnych rzeczy, że moja głowa jest smażona. – Jason