Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.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

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可排序占位符位置(索引)_Jquery_Jquery Ui_Jquery Ui Sortable - Fatal编程技术网

jQuery可排序占位符位置(索引)

jQuery可排序占位符位置(索引),jquery,jquery-ui,jquery-ui-sortable,Jquery,Jquery Ui,Jquery Ui Sortable,我想在可排序占位符中显示可排序元素的位置或索引。它在拖动第一个元素时起作用,而不是与其他元素一起拖动位置0而不是1 请检查: 我做错了什么?可能是因为它在拖动元素之前附加了新元素 让我们试试这个代码 var position; $(".elements-sortable").sortable({ placeholder: "sortable-placeholder", opacity: "0.6", start: function(event, ui) { position = p

我想在可排序占位符中显示可排序元素的位置或索引。它在拖动第一个元素时起作用,而不是与其他元素一起拖动位置0而不是1

请检查:


我做错了什么?

可能是因为它在拖动元素之前附加了新元素

让我们试试这个代码

var position;
$(".elements-sortable").sortable({

placeholder: "sortable-placeholder",
opacity: "0.6",

start: function(event, ui) {

    position = position = Number($(".elements-sortable > div:not(.ui-sortable-helper)").index(ui.placeholder)+1);
    $(".sortable-placeholder").html('Drop me at position ' + position);

},

change: function(event, ui) {
    position = position = Number($(".elements-sortable > div:not(.ui-sortable-helper)").index(ui.placeholder)+1);
    $(".sortable-placeholder").html('Drop me at position ' + position);
}
});

我在

上测试了它,可能是因为它在拖动元素之前添加了新元素

让我们试试这个代码

var position;
$(".elements-sortable").sortable({

placeholder: "sortable-placeholder",
opacity: "0.6",

start: function(event, ui) {

    position = position = Number($(".elements-sortable > div:not(.ui-sortable-helper)").index(ui.placeholder)+1);
    $(".sortable-placeholder").html('Drop me at position ' + position);

},

change: function(event, ui) {
    position = position = Number($(".elements-sortable > div:not(.ui-sortable-helper)").index(ui.placeholder)+1);
    $(".sortable-placeholder").html('Drop me at position ' + position);
}
});

我在

上对它进行了测试,我正在寻找一个类似挑战的解决方案,发现了这个问题,经过一点调整和修正,它成功了

$('.elements-sortable').sortable({
    placeholder: 'sortable-placeholder',
    opacity: 0.6,
    helper: 'clone',
    sort: function(event,ui){
        $(ui.placeholder).html(Number($('.elements-sortable > div:visible').index(ui.placeholder)+1));
    }
});

我正在寻找一个类似挑战的解决方案,发现了这个问题,经过一些调整和修正,它成功了

$('.elements-sortable').sortable({
    placeholder: 'sortable-placeholder',
    opacity: 0.6,
    helper: 'clone',
    sort: function(event,ui){
        $(ui.placeholder).html(Number($('.elements-sortable > div:visible').index(ui.placeholder)+1));
    }
});
试试这个

试试这个


是的,我肯定可以这样做,但是没有一种标准的方法可以在所有元素上获得相同的索引位置吗?我已经修复了一些代码,但我认为有时它有一个错误,当我将div移动到第一个位置时,我无法解释。是的,我肯定可以这样做,但是,难道没有一种标准的方法可以在所有元素上获得相同的索引位置吗?我已经修复了一些代码,但我认为有时它有一个错误,我无法解释何时将div移动到第一个位置。没有。这不是这里需要的,不是。这不是这里需要的。