【发布时间】:2018-12-13 19:05:11
【问题描述】:
$('.parent').sortable({
containment: "parent",
tolerance: "pointer",
axis: "x"
});
$('button').on('click', function(){
var str = $('#store').html();
$(str).insertBefore($('.parent').eq(0));
});
.parent{
background:silver;
margin:9px 0;
}
.title{
background:gold;
display:inline-block;
width:25%;
cursor:cell;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<div id='store'>
<div class='parent'>
<div class='title'>lorem</div>
<div class='title'>ipsum</div>
</div>
</div>
<br>
<button>CLICK</button>
如何使插入的项目可排序?
没有任何作用。
【问题讨论】:
-
添加项目后需要在 sortable 上运行
refresh:api.jqueryui.com/sortable/#method-refresh -
您想将这两个项目克隆到同一个列表中吗?还是您打算制作一个新清单?
-
@Twisty,我需要新项目以与旧项目相同的方式排序 - 在其父项内。
$( ".selector" ).sortable( "refresh" );不起作用。 -
看我回答的第二部分。
标签: jquery jquery-ui jquery-ui-sortable