嗨,我需要做到这一点..
我有一组可放下的物品(基本上是在服装上放设计),在放一个克隆品。
如果我不喜欢放置的对象(设计)-我想通过执行诸如hidden删除它。
但是我做不到。
请帮我..
这是代码
var clone;
$(document).ready(function(){
$(".items").draggable({helper: 'clone',cursor: 'hand'});
$(".droparea").droppable({
accept: ".items",
hoverClass: 'dropareahover',
tolerance: 'pointer',
drop: function(ev, ui)
{
var dropElemId = ui.draggable.attr("id");
var dropElem = ui.draggable.html();
clone = $(dropElem).clone(); // clone it and hold onto the jquery object
clone.id="newId";
clone.css("position", "absolute");
clone.css("top", ui.absolutePosition.top);
clone.css("left", ui.absolutePosition.left);
clone.draggable({ containment: 'parent' ,cursor: 'crosshair'});
$(this).append(clone);
alert("done dragging ");
/lets assume I have a delete button when I click that clone should dissapear so that I can drop another design - but the following code has no effect
//and the item is still visible , how to make it dissapear ?
$('#newId').css("visibility","hidden");
}
});
});
最佳答案
由于.clone()返回jQuery对象。 clone.id =“ newId”在jQuery对象上设置属性,而不是DOM元素。由于DOM元素没有id属性。 $('#newId')。length应该返回null。在Firebug控制台中测试
采用:
clone.attr('id', 'newId')
在克隆对象的DOM元素上设置ID。