简体   繁体   English

如何在jQuery中找到所有删除的元素

[英]How to find all the dropped elements in jQuery

    .dropped
    {
        position: static !important;
    }
    #dvSource
    {
        padding: 5px;
        min-height: 100px;
        width: 470px;
        margin-top: 300px;
    }
    #dvSource img {
        padding-left: 10px;
    }
    .one {
        left: 20px;
    }
    .nodrop {
        padding-left: 20px;
    }
    #dvDest
    {
        background:url(images/line_background.png);
        min-height: 100px;
        width: 110px;       
        float: left;    
        margin-left: 20px;          
    }

    #dvDest1
    {
        background:url(images/line_background.png);
        display: inline-block;
        min-height: 100px;
        width: 110px;
        margin-left: 10px;          
    }
    #dvDest2
    {
        background:url(images/line_background.png);
        display: inline-block;
        min-height: 100px;
        width: 110px;
        margin-left: 10px;          
    }

    #otherimgs {
        float: left;

    }
    .allcontent {
        width: 700px;
        margin-top: 120px;
    }
    .contain {
        text-align: center;

    }
    .contain img {
        margin-left: 20px;

    }
    .popup {
        position: absolute;
        top: 280px;
        right: 480px;
     }
     .popup img {
        width: 435px;
        height: 134px;

     }
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.8.24/jquery-ui.min.js" type="text/javascript"></script>
<script type="text/javascript">
function hideerror() {
    $('.popup').remove();
}

    $(function () {
        $("#dvSource img.one").draggable({
            revert: function () {
                $(this).delay(600);
                return true
            },
            revertDuration: 500,
            refreshPositions: true,              
            stop: function (event, ui) {
                $("body").append('<div class="popup"><img src="images/tryagain.png"></div>'); setTimeout(function(){hideerror()},1200);
            }
        });

        $("#dvSource img.one1").draggable({
            revert: function () {
                $(this).delay(600);
                return true
            },
            revertDuration: 500,
            refreshPositions: true,
            stop: function (event, ui) {
                $("body").append('<div class="popup"><img src="images/tryagain.png"></div>'); setTimeout(function(){hideerror()},1200);
            }
        });
        $("#dvSource img.one2").draggable({
            revert: function () {
                $(this).delay(600);
                return true
            },
            revertDuration: 500,
            refreshPositions: true,
            stop: function (event, ui) {
                $("body").append('<div class="popup"><img src="images/tryagain.png"></div>'); setTimeout(function(){hideerror()},1200);
            }
        });

        $("#dvDest").droppable({
        accept: '#dvSource img.one',
            drop: function (event, ui) {
                if ($("#dvDest img").length == 0) {
                    $("#dvDest").html("");
                }
                ui.draggable.addClass("dropped");
                $("#dvDest").append(ui.draggable);                  
                $("body").append('<div class="popup"><img src="images/greatwork.png"></div>'); setTimeout(function(){hideerror()},1300);
                $( this ).hideerror();
            }
        });
        $("#dvDest1").droppable({
        accept: '#dvSource img.one1',
            drop: function (event, ui) {
                if ($("#dvDest1 img").length == 0) {
                    $("#dvDest1").html("");
                }
                ui.draggable.addClass("dropped");
                $("#dvDest1").append(ui.draggable);
                $("body").append('<div class="popup"><img src="images/greatwork.png"></div>'); setTimeout(function(){hideerror()},1300);
                $( this ).hideerror();
            }
        });
        $("#dvDest2").droppable({
        accept: '#dvSource img.one2',
            drop: function (event, ui) {
                if ($("#dvDest2 img").length == 0) {
                    $("#dvDest2").html("");
                }
                ui.draggable.addClass("dropped");
                $("#dvDest2").append(ui.draggable);
                $("body").append('<div class="popup"><img src="images/greatwork.png"></div>'); setTimeout(function(){hideerror()},1300);                
                setTimeout(function() {
                  window.location.href = "6.htm";
                }, 1500);
                $( this ).hideerror();
            }
        });

    });
</script>
<div class="allcontent">
<div id="otherimgs">
    <img alt="" src="images/large_ball.png" />
    <img alt="" src="images/medium_ball.png" />
    <img alt="" src="images/small_ball.png" />
</div>
<div class="contain">
    <div id="dvDest"></div>
    <div id="dvDest1"></div>
    <div id="dvDest2"></div>
</div>  
</div>
<div id="dvSource">
    <img class="one" alt="" src="images/large_ball.png" />
    <img class="one1" alt="" src="images/medium_ball.png" />
    <img class="one2" alt="" src="images/small_ball.png" />
</div>

here i have made 3 elements droppable to their respective destination place ..i want to redirect the page to another only when all the 3 elements are dropped in their places..how to find whether the element is dropped.. can anyone help me with this?? 在这里,我已将3个元素放置到各自的目标位置。.我仅在将所有3个元素都放置在其位置时才将页面重定向到另一个。.如何查找是否放置了元素..任何人都可以帮助我这个??

check this fiddle for demo http://jsfiddle.net/karthikchandran/stxzqskq/3/ 检查此小提琴以获得演示http://jsfiddle.net/karthikchandran/stxzqskq/3/

You can use jQuery to count the number of elements that are dropped: 您可以使用jQuery来计算删除的元素数:

var count = $(".dropped").length;

You can check this and perform an action if the expected number are dropped: 您可以检查一下,如果期望的数字被删除,可以执行以下操作:

if (count === 3) { ... }

Fiddle Demo try this 小提琴演示试试

function checked()
        {
        var i = 0;
        if($("#dvDest").children("img").hasClass("dropped"))
        {
        i++;
        }
        if($("#dvDest1").children("img").hasClass("dropped"))
        {
        i++;
        }
        if($("#dvDest2").children("img").hasClass("dropped"))
        {
        i++;
        }
        console.log(i);
        if(i ==3)
        {
        window.location.href="http://google.com";
        }
        }

create a checked() function and call it on each droppable function it will get redirected to the given linked as shown in fiddle demo but in fiddle it won't get redirect. 创建一个checked()函数并在每个droppable函数上调用它,它将被重定向到给定的链接,如小提琴演示所示,但在小提琴中,它不会被重定向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 拖动jQuery中拖放元素的克隆 - Drag the clone of dropped elements in jQuery 放弃所有玩家后,如何保存拖放元素VALUE(足球经理) - How can I save dragged & dropped elements VALUE after dropped all players (soccer manager) 在jQuery中,如何找到与给定字符串匹配的所有元素? - In jQuery, how to find all elements matching given strings? 如何通过jQuery查找属于动态添加的类的所有元素? - How to find all elements that belong to a dynamically added class by jquery? 如何使用jQuery查找具有特定类的所有div元素 - How to find all div elements with specific class using jquery jQuery UI Draggable和Droppable:删除页面上的所有可拖动元素时,调用一个函数 - jQuery UI Draggable and Droppable: Call a function when all draggable elements on the page are dropped 放下所有可拖动元素时显示按钮/播放消息。 Adobe Edge Animate Javascript / Jquery - Show button/Play Message when all draggable elements are dropped. Adobe Edge Animate Javascript/Jquery jQuery-获取放置元素的相对位置和属性 - jQuery - get relative position and attribute of dropped elements 使用jquery中数据表的正则表达式查找所有元素 - Find all elements with regex of a datatable in jquery jQuery:找到所有元素<input type="“number”"> - jQuery: find all elements with <input type=“number”>
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM