Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [JavaScript]Wyciaganie data-attrubute z upuszczonego elementu na (droppable)
Forum PHP.pl > Forum > Przedszkole
goartur
Witam. Wiec chce aby po upuszczeniu elementu na element droppable zostal znaleziony data attribute upuszczonego elementu,

Kod:

  1. <html lang="en">
  2. <head>
  3. <meta charset="utf-8">
  4. <title>jQuery UI Droppable - Default functionality</title>
  5. <link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  6. <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
  7. <script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
  8. <link rel="stylesheet" href="/resources/demos/style.css">
  9. #draggable { width: 100px; height: 100px; padding: 0.5em; float: left; margin: 10px 10px 10px 0; }
  10. #droppable { width: 150px; height: 150px; padding: 0.5em; float: left; margin: 10px; }
  11. </style>
  12. $(function() {
  13. $( "#draggable" ).draggable();
  14. $( "#droppable" ).droppable({
  15. drop: function( event, ui ) {
  16. $( this )
  17. .addClass( "ui-state-highlight" )
  18. .find( "p" )
  19. .html( "Dropped!" );
  20. console.log($(ui.item).attr('data-parent'));
  21. }
  22. });
  23. });
  24. </script>
  25. </head>
  26. <body>
  27.  
  28. <div id="draggable" data-parent="sdsd" class="ui-widget-content">
  29. <p>Drag me to my target</p>
  30. </div>
  31.  
  32. <div id="droppable" class="ui-widget-header">
  33. <p>Drop here</p>
  34. </div>
  35.  
  36.  
  37. </body>
  38. </html>


Uzywac w tym momecie :
console.log($(ui.item).attr('data-parent'));

Lecz dostaje komunikat undefined
trueblue
  1. $(ui.draggable).attr('data-parent')

lub:
  1. $(ui.draggable).data('parent')

A przede wszystkim dokumentacja: http://api.jqueryui.com/droppable/#event-drop
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.