Jquery可以按钮排序

时间:2014-02-24 21:52:22

标签: jquery jquery-ui-sortable

我有一堆按钮,我想要排序(例如,我可以随意重新排列)。这是一个示例html代码。这些按钮是动态添加的,因此在添加和删除按钮后需要排序。我已经尝试过使用JQuery排序但没有运气。有关如何做的任何建议吗?

    <div id="fav" class="ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom" aria-labelledby="ui-accordion-accordion-header-0" role="tabpanel" aria-expanded="false" aria-hidden="true" style="display: none;">
        <div id="MSFT" symbol="MSFT" exchange="NASDAQ" class="stockButton">
            MSFT
            <span symbol="MSFT" exchange="NASDAQ" class="remove-button">
                x
            </span>
        </div>

        <div id="GOOG" symbol="GOOG" exchange="NASDAQ" class="stockButton">
            GOOG
            <span symbol="GOOG" exchange="NASDAQ" class="remove-button">
                x
            </span>
        </div>

        <div id="YHOO" symbol="YHOO" exchange="NASDAQ" class="stockButton">
            YHOO
            <span symbol="YHOO" exchange="NASDAQ" class="remove-button">
                x
            </span>
        </div>

1 个答案:

答案 0 :(得分:1)

添加适当的库后,尝试:

$(function() {
$( "#fav" ).sortable();

$( "#fav" ).append('<span symbol="NEW" exchange="ECH" class="remove-button">x</span>');

});

请参阅此http://jsfiddle.net/x4sny/