【发布时间】:2013-12-05 07:07:37
【问题描述】:
我在 jquery 中有一些带有可拖放元素的代码。
这是我的 jsfiddle 链接 - http://jsfiddle.net/hirenwebdp/Mf6zJ/333/
我想通过为
创建一个函数来优化这段代码drop: function(event, ui) {
var self = $(this);
self.find(".placeholder").remove();
var productid = ui.draggable.attr("data-id");
if (self.find("[data-id=" + productid + "]").length) return;
$("<li></li>", {
"text": ui.draggable.text(),
"data-id": productid
}).appendTo(this);
$("#equal").hide();
// To remove item from other shopping chart do this
var cartid = self.closest('.shoppingCart').attr('id');
$(".shoppingCart:not(#"+cartid+") [data-id="+productid+"]").remove();
var isAllFilled = true;
$(".shoppingCart").each(function(){
if($(this).find('ol .placeholder').length > 0)
{
isAllFilled = false;
return
}
});
if(isAllFilled)
{
$("#equal").show();
$("#equal").html("Congratulation! You have entered each block in correct place.");
}
所以我编写了代码但无法正常工作。元素被拖动但不可放置。
优化后的jsfiddle链接为http://jsfiddle.net/Mf6zJ/486/
那么如何解决这个问题。 请先检查两个 jsfiddle 链接,以便你们了解我面临的问题。
请帮忙。
【问题讨论】:
标签: javascript jquery performance jquery-ui