简体   繁体   English

获取删除的div的ID,并隐藏所有没有该类的所有div

[英]get ID of dropped div and hide all other divs without this class

Sorry for the confusing title, I hope I can explain. 对不起,标题令人困惑,希望我能解释一下。

http://thetally.efinancialnews.com/tallyassets/suebanks/suebanks.html http://thetally.efinancialnews.com/tallyassets/suebanks/suebanks.html

In this example you can drag a red box from the right into the grey box at the top left, each red box has a unique ID. 在此示例中,您可以将一个红色框从右侧拖动到左上方的灰色框,每个红色框都有唯一的ID。 When this red box is dropped in, I would like all the black boxes below to disappear EXCEPT the ones who's CLASS matches the unique ID of the red square. 放下这个红色框后,我希望下面的所有黑色框消失,除非CLASS匹配红色框唯一ID的那些。

The first box has an ID of 'barclays', as do 2 of the black boxes, so those 2 should remain 第一个框的ID为“ barclays”,黑框的2个也是如此,因此应保留这2个

The second has an ID of lloyds, so only 1 of those black boxes should remain. 第二个具有劳埃德(Lloyds)的ID,因此应仅保留其中一个黑匣子。

Here is the javascript code I am using: 这是我正在使用的javascript代码:

$(init);
function init() {
    $('.draggable').draggable({
        containment: '#maincontain',
        stack: '.bankbox div',
        cursor: 'move',
        revert: true
    });
    $('.judge').droppable({
        drop: handleDropEvent
    });
}

function handleDropEvent(event, ui) {
    var draggable = ui.draggable;
    ui.draggable.position({
        of: $(this),
        my: 'center bottom',
        at: 'center bottom'
    });
    alert('The square with ID "' + draggable.attr('id') + '" was dropped onto me!');
}

...so what I need to do is get the 'draggable.attr('id') as is displayed in the alert, then create something in the handleDropEvent that says... HIDE all divs in .lawyers div, except those with a class equal to draggable.attr('id') ...所以我需要做的是获取警报中显示的'draggable.attr('id'),然后在handleDropEvent中创建如下内容:隐藏.lawyers div中的所有div,除了那些一个等于draggable.attr('id')的类

I've tried hacking it together but not getting the result I'm after 我尝试过一起破解,但没有得到我想要的结果

Hope it isnt too confusing, thanks for any advice 希望它不会太混乱,谢谢您的任何建议

untested but your handleDropEvent should look similar to this... 未经测试,但您的handleDropEvent应该看起来类似于此...

function handleDropEvent(event, ui) {
    var draggable = ui.draggable;
    ui.draggable.position({
        of: $(this),
        my: 'center bottom',
        at: 'center bottom'
    });
    alert('The square with ID "' + draggable.attr('id') + '" was dropped onto me!');

    //Add these lines:
    var lawyers = $('.lawyers .lawyer');
    lawyers.not('.'+draggable.attr('id')).hide();
    lawyers.filter('.'+draggable.attr('id')).show();
}

here is a working fiddle: http://jsfiddle.net/g30rg3/c3Dt9/1/ 这是一个有效的小提琴: http : //jsfiddle.net/g30rg3/c3Dt9/1/

Check this page: 检查此页面:

http://api.jqueryui.com/droppable/#event-drop http://api.jqueryui.com/droppable/#event-drop

Hmm - i usually have the droppable area named droppable ... 嗯-我通常有一个名为droppable的droppable区域...

Think it will be something like this: 认为会是这样的:

$( ".droppable" ).droppable({
  drop: function( event, ui ) 
{
$( ".blackBox" ).addClass('hideBox');
}

});

Then use the hideBox class that has now appended itself to blackBox to hide?? 然后使用现在已将自身附加到blackBox的hideBox类隐藏?

Check the info in that link though i think it might be what you need. 检查该链接中的信息,尽管我认为这可能是您所需要的。 Or pop it into codepen so people can play :) 或将其弹出到Codepen中,以便人们可以玩:)

You just have to add 您只需要添加

$('.lawyers').not('.' + draggable.attr('id')).hide();

after the ui.draggable.position command. ui.draggable.position命令之后。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM