我有3个单独的(有单独的类名)项放到一个大的div中。我需要drop函数来运行一些不同的东西,这取决于我将哪个draggble项放到droppable中。
这是我的代码。
$(".gridster").droppable({
accept: ".dragExist,.dragDefault, .dragLaunch",
hoverClass: "drop-state",
drop: function(event,ui){
var currentId = $(ui.draggable).attr("class");
if(currentId == "dragExist"){
gridster.add_widget.apply(gridster, ['<li>new Widget', 1, 1]);
console.log(event);
event.preventDefault();
}
}
});如果我可以让第一个If语句工作,我会添加另外两个类,但我似乎没有得到正确的结果。谢谢你!!
发布于 2014-05-15 04:28:55
一个简单的解决方案是在每个可拖动元素的mousedown事件上添加一个类,假设是'selected-item‘。然后,在drop事件中,您可以很容易地识别使用“selected-item”类拖动的元素,并在最后删除该类。
https://stackoverflow.com/questions/23663834
复制相似问题