我有一个小部件,我可以在其中将物品放入垃圾桶。我希望能够在 drop 事件中为丢弃在垃圾桶中的每个项目添加一个唯一的 ID。我该怎么做?有没有办法让输出值成为列表项的实际名称?谢谢!下面是我的代码:
$(function() {
var $gallery = $( "#gallery" ),
$trash = $( "#trash" );
$( "li", $gallery ).draggable({
cancel: "a.ui-icon",
revert: "invalid",
containment: $( "#demo-frame" ).length ? "#demo-frame" : "document", // stick to demo-frame if present
helper: "clone",
cursor: "move"
});
$trash.droppable({
accept: "#gallery > li",
activeClass: "ui-state-highlight",
drop: function( event, ui ) {
deleteImage( ui.draggable );
}
});
$gallery.droppable({
accept: "#trash li",
activeClass: "custom-state-active",
drop: function( event, ui ) {
recycleImage( ui.draggable );
}
});
HTML
<div class="demo ui-widget ui-helper-clearfix">
<ul id="gallery" class="gallery ui-helper-reset ui-helper-clearfix">
<li class="ui-widget-content ui-corner-tr" a href="link/to/trash/script/when/we/have/js/off">
<h5 class="fpheader">Red</h5>
</li>
<li class="ui-widget-content ui-corner-tr">
<h5 class="fpheader">Orange</h5>
</li>
<li class="ui-widget-content ui-corner-tr">
<h5 class="fpheader"Yellow</h5>
</li>
<li class="ui-widget-content ui-corner-tr">
<h5 class="fpheader">Green</h5>
</li>
<li class="ui-widget-content ui-corner-tr">
<h5 class="fpheaderr">Blue</h5>
</li>
<li class="ui-widget-content ui-corner-tr">
<h5 class="fpheader">Purple</h5>
</li>
<li class="ui-widget-content ui-corner-tr">
<h5 class="fpheader">White</h5>
</li>
</ul>
</div>