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
Javascript 单击jQuery UI可排序_Javascript_Jquery Ui - Fatal编程技术网

Javascript 单击jQuery UI可排序

Javascript 单击jQuery UI可排序,javascript,jquery-ui,Javascript,Jquery Ui,我的jQuery UI排序功能运行良好,但我还想添加一个基本的单击操作,以使可拖动项发生更改。我已禁用拖动。我想要的是在第一个中,如果单击了单击区域,那么可排序的将移动到第二个,就像我将其拖过一样。相同的交易如果在第二个中单击单击区域,它将移动到第一个。我为测试创建了一个JS提琴: 如有任何建议,将不胜感激。谢谢。这里是你的起点 $("#unassigned_list, #recipients_list").sortable({ connectWith: ".connected_sort

我的jQuery UI排序功能运行良好,但我还想添加一个基本的单击操作,以使可拖动项发生更改。我已禁用拖动
。我想要的是在第一个
中,如果单击了单击区域,那么可排序的
  • 将移动到第二个
    ,就像我将其拖过一样。相同的交易如果在第二个
    中单击单击区域,它将移动到第一个
    。我为测试创建了一个JS提琴:


    如有任何建议,将不胜感激。谢谢。

    这里是你的起点

    $("#unassigned_list, #recipients_list").sortable({
        connectWith: ".connected_sortable",
        items: "li",
        handle: ".draggable_area",
        stop: function(event, ui) {
            updateLi(ui.item);
        }
    }).disableSelection().on("click", ".click_area", function() {
        // First figure out which list the clicked element is NOT in...
        var otherUL = $("#unassigned_list, #recipients_list").not($(this).closest("ul"));
        var li = $(this).closest("li");
    
        // Move the li to the other list. prependTo() can also be used instead of appendTo().
        li.detach().appendTo(otherUL);
    
        // Finally, switch the class on the li, and change the arrow's direction.
        updateLi(li);
    });
    
    function updateLi(li) {
        var clickArea = li.find(".click_area");
        if (li.closest("ul").is("#recipients_list")) {
            li.removeClass("ui-state-default").addClass("ui-state-highlight");
            clickArea.html('←');
        } else {
            li.removeClass("ui-state-highlight").addClass("ui-state-default");
            clickArea.html('→');
        }    
    }
    ​
    
    .on('click', '.click_area', function(){
        $(this).parent().appendTo($("#unassigned, recipients").not($(this).closest("ul")));
    })
    
    诀窍在于单击处理程序位于父容器上,而不是单个子容器上,因此当它们被移动时,您不需要继续管理它们的处理程序

    您所需要做的就是更新样式


    此解决方案非常有效。我还有一个问题。类在单击时会发生变化,这很好,但该操作是否也可以应用于“可拖动”状态?当我拖动
  • 时,它不会更改我知道上面的脚本无法处理的类,我只是想知道如何实现这一点。我已经更新了我的JS小提琴。谢谢。@HelpInspireMe我更新了我的答案,希望能回答你的问题。请注意,我现在使用的是.on(),而不是.find().click(),这是jQuery新版本的建议。我非常感谢您在这方面的帮助。如果有人希望看到这里的最终产品是我计划保存的JS提琴。