2

当我将元素div拖放到ul时,我想将div更改为li

演示http://jsfiddle.net/7fEQs/

脚本

$(function() {
    $( "#sortable" ).sortable({
        revert: true
    });
    $( "#draggable" ).draggable({
        connectToSortable: "#sortable",
        helper: "clone",
        revert: "invalid"
    });
    $( "ul, li" ).disableSelection();
});

非常感谢。

4

1 回答 1

1

更新演示http://jsfiddle.net/yyene/7fEQs/7/

查询

$(function() {
    $( "#sortable" ).sortable({
        revert: true,
        receive: function(event, ui) {
            $(this).find('div').removeClass('ui-state-highlight ui-draggable').css({'display':''});            
            
            var html = [];
            $(this).find('div').each(function() {
                html.push('<li class="ui-state-default">' + $(this).text() + '</li>');
            });
            $(this).find('div').replaceWith(html.join(''));
        }
    });
    $( "#draggable" ).draggable({
        connectToSortable: "#sortable",
        helper: "clone",
        revert: "invalid"
    });
    $( "ul, li" ).disableSelection();
});
于 2013-06-18T08:09:54.163 回答