这是ul将删除新li的地方:
<ul id="sortable2" class="connectedSortable">
<li class="ui-state-default li-cat">Appetizers</li>
<li class="ui-state-default li-cat">Soups</li>
</ul>
这是ul将被拖动的地方:
<ul id="sortable1" class="connectedSortable">
<li class="ui-state-default ap dd">Cobb Salad</li>
<li class="ui-state-default soup dd">Gazpacho</li>
<li class="ui-state-default salad dd">Prime Rib</li>
</ul>
jqueryui函数连接两个列表:
$(function() {
$( "#sortable1, #sortable2" ).sortable({
connectWith: ".connectedSortable",
}).disableSelection();
});
我只想在将新元素(li)添加到ul时调用javascript函数。我使用jqueryui进行拖放排序。
答案 0 :(得分:0)
use change property in jquery sortable, so whenever sortable list is changing this change property will trigger automatically.....
(function($) {
var beforeChangeUlLen = $("#sortable2").length;
$( "#sortable1, #sortable2" ).sortable({
connectWith: ".connectedSortable",
change: function(){
var afterChangeUlLen = $("#sortable2").length;
if(beforeChangeUlLen > afterChangeUlLen){
/*Add you function after new li is added to ul*/
}
}
}).disableSelection();
})(jQuery);