关于jQuery可拖放/可拖放的问题
我修改了一个示例照片管理器应用程序 我有来自查询的员工记录,而不是照片。我的版本将允许经理将员工标记为休假或工作。我做的一件事是包括员工ID,如关于jQuery可拖放/可拖放的问题,jquery,Jquery,我修改了一个示例照片管理器应用程序 我有来自查询的员工记录,而不是照片。我的版本将允许经理将员工标记为休假或工作。我做的一件事是包括员工ID,如。我从event.target获取ID。这适用于单击功能,但不适用于“可拖放”功能。这是单击功能的功能: $('ul.gallery > li').click(function(ev) { var $item = $(this); var $unid = ev.target; var $target = $(ev.target); if ($
。我从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)向我提供[对象]。这个物体里有什么?我怎样才能从中得到好处
感谢在文档中,它向您展示了它提供的附加jQuery对象:
因此,按以下方式更改代码应该是可行的:
$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);
}
});
我认为这解决了我的问题:
drop: function(ev, ui) {
var $unid = $(ui.draggable).attr('id');
recycleImage(ui.draggable,$unid);
}
如果我使用这个:
var $unid = ui.draggable.find('id');
然后我得到[对象]
此外,我还必须修改:
$('ul.gallery > li').click(function(ev) {
var $item = $(this);
var $unid = $(this).attr('id');
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;
});
很有魅力:)对不起,我的代码出错了。。。查找('id')而不是
,它应该是.attr('id')
。我想我们需要在可拖动对象中找到
标记,但后来我注意到您没有包含任何HTML。不管怎样,我很高兴你得到了答案:)
$('ul.gallery > li').click(function(ev) {
var $item = $(this);
var $unid = $(this).attr('id');
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;
});