我修改了示例照片管理器应用程序。
我有来自查询的员工记录,而不是照片。我的版本将允许经理将员工标记为正在度假或在工作。我做的一件事就是包含员工 ID,例如 <a href="123">
。我从 event.target 获取 id。这适用于点击功能,但不适用于“可放置”功能。这就是我的点击功能:
$('ul.gallery > li').click(function(ev) {
var $item = $(this);
var $unid = ev.target;
var $target = $(ev.target);
if ($target.is('a.ui-icon-suitcase')) {
deleteImage($item,$unid);
} else if ($target.is('a.ui-icon-arrowreturnthick-1-w')) {
recycleImage($item,$unid);
}
return false;
});
ev.target 正确给出了员工 ID。
当我在可删除函数之一中尝试相同的操作时:
$gallery.droppable({
accept: '#suitcase li',
activeClass: 'custom-state-active',
drop: function(ev, ui) {
var $unid = ev.target;
alert($unid);
recycleImage(ui.draggable,$unid);
}
});
警报(ui)给了我[对象]。这个物体里有什么?我如何从中获取href?
谢谢
最佳答案
在 jQuery UI droppable文档显示它提供了额外的 jQuery 对象:
* ui.draggable - current draggable element, a jQuery object. * ui.helper - current draggable helper, a jQuery object * ui.position - current position of the draggable helper { top: , left: } * ui.offset - current absolute position of the draggable helper { top: , left: }
因此,按如下方式更改代码应该可行:
$gallery.droppable({
accept: '#suitcase li',
activeClass: 'custom-state-active',
drop: function(ev, ui) {
var $unid = ui.draggable.attr('id');
alert($unid);
recycleImage(ui.draggable, $unid);
}
});
关于jquery - 关于 jQuery droppable/draggable 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2789844/