嗨,我需要实现这个目标..
我有一组可转换的元素(基本上我是在服装上转换设计)并且我正在转换一个克隆..
如果我不喜欢放置的对象(设计) - 我想通过执行隐藏之类的操作来删除它。
但我无法做到这一点。
请帮助我..
<小时/>这是代码
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。
关于Jquery 拖放和克隆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2100896/