2016-08-24 95 views
0

我可以得到这个工作使用鼠标。我无法使用键盘使它工作。jQueryUI丢弃警报时丢弃 - 键盘焦点

运作方式及使用鼠标跌落时增加了一个消息:

$('.drop_01').droppable ({ 
    drop: function() { 
     $('span.movedItem1').remove(); 
     $(this).prepend('<span class=\"movedItem1\">Item moved to Program philisophy drop area Vision/mission.</span>'); 
    } 
}); 

我需要使用键盘组合键Alt + 1时一样发生。我有这个,并尝试了几个变化,但不能得到它的工作。该项目仍然移动到丢弃的位置,但消息不显示。

$(".activity").on("keydown", "#activity_contents a", function (e) { 
if(e.altKey && (e.which === 49)) { 

$('.drop_01').droppable ({ 
    drop: function() { 
     $('span.movedItem1').remove(); 
     $(this).prepend('<span class=\"movedItem1\">Item moved to Program philisophy drop area Vision/mission.</span>'); 
    } 
}); 

} 
}); 

如果这是可以实现的,有人可以帮忙。为了澄清这一点,只是显示消息的拖放功能是很多额外的代码没有发布。

回答

0

我看着这个错误的方式。我的解决方案(尽管有点不整齐)是:

// CtRL key moves something to next column 
$(".activity").on("keydown", ".connected-sortable.draggable li", function (event) { 
    var $this = $(this) 
     , key = event.keyCode || e.which 
     , $holder = $this.parents(".activity") 
     , $selectedul = $this.parent() 
     , $availableuls = $holder.find(".connected-sortable") 
     , currentlistindex = $selectedul.data("list-index") 
     , nextlistindex = currentlistindex + 1 
     , $nextul = $holder.find(".connected-sortable[data-list-index='" + nextlistindex + "']") 
     , $originalul = $holder.find(".connected-sortable[data-list-index='0']"); 

    if ($nextul.length == 0) { 
     $nextul = $originalul; 

    } 

    if(nextlistindex === 1) { 
     $('span.movedItema').remove(); 
     $('span.movedItemb').remove(); 
     $('span.movedItemc').remove(); 
     $('span.movedItemd').remove(); 
     $(this).focus().prepend('<span class=\"movedItema offscreenText\">Item moved to Program philisophy drop area Vision/mission.</span>'); 
    } 
    if(nextlistindex === 2) { 
     $('span.movedItema').remove(); 
     $('span.movedItemb').remove(); 
     $('span.movedItemc').remove(); 
     $('span.movedItemd').remove(); 
     $(this).focus().prepend('<span class=\"movedItemb offscreenText\">Item moved to Program philisophy drop area Beliefs/values.</span>'); 
    } 
    if(nextlistindex === 3) { 
     $('span.movedItema').remove(); 
     $('span.movedItemb').remove(); 
     $('span.movedItemc').remove(); 
     $('span.movedItemd').remove(); 
     $(this).focus().prepend('<span class=\"movedItemc offscreenText\">Item moved to Program philisophy drop area Strategies.</span>'); 
    } 
    if(nextlistindex === 4) { 
     $('span.movedItema').remove(); 
     $('span.movedItemb').remove(); 
     $('span.movedItemc').remove(); 
     $('span.movedItemd').remove(); 
     $(this).focus().prepend('<span class=\"movedItemd offscreenText\">Item moved back to Program philisophy Factors list.</span>'); 
    }