Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery ui 如何制作具有不同功能的可拖动div?_Jquery Ui_Jquery Plugins_Drag And Drop_Draggable_Jquery Ui Droppable - Fatal编程技术网

Jquery ui 如何制作具有不同功能的可拖动div?

Jquery ui 如何制作具有不同功能的可拖动div?,jquery-ui,jquery-plugins,drag-and-drop,draggable,jquery-ui-droppable,Jquery Ui,Jquery Plugins,Drag And Drop,Draggable,Jquery Ui Droppable,我有四个可以拖动的div。还有一个潜水艇,我把匕首扔在那里。我的代码基本上只是一个API,我下载并修改了jQuery网站的一些表单 我的问题是,所有div在被删除时都具有相同的功能。如何为单个div生成单个函数 看起来是这样的: $(function() { $("#draggable").draggable({ revert: "invalid" }); $("#draggable2").draggable({ revert: "invalid" }); $("#draggable3").dr

我有四个可以拖动的div。还有一个潜水艇,我把匕首扔在那里。我的代码基本上只是一个API,我下载并修改了jQuery网站的一些表单

我的问题是,所有div在被删除时都具有相同的功能。如何为单个div生成单个函数

看起来是这样的:

$(function() {
$("#draggable").draggable({ revert: "invalid" });
$("#draggable2").draggable({ revert: "invalid" });
$("#draggable3").draggable({ revert: "invalid" });
$("#draggable4").draggable({ revert: "invalid" });

$("#droppable").droppable({
    activeClass: "ui-state-hover",
    hoverClass: "ui-state-active",
    drop: function(event, ui) {
        if (document.getElementById('draggable')){
            window.location.replace("http://www.example.com");      
            }
        if (document.getElementById('draggable2')){
            window.location.replace("http://www.example2.com");     
            }
        if (document.getElementById('draggable3')){
            window.location.replace("http://www.example3.com");     
            }
        if (document.getElementById('draggable4')){
            window.location.replace("http://www.example4.com");     
            }
        }
    });
});
在这个代码中没有运气。有什么想法吗

提前谢谢


请注意,VG在您的“如果”语句中,您需要执行以下操作:

if(ui.draggable.attr('id') === 'draggable')
{
    // do stuff
}

谢谢,伙计,成功了。我对Stackoverflow有点陌生,但令人惊讶的是,获取信息的速度和容易程度是如此之快,好的信息!:我会小心的。