0

10 個のテキスト入力フィールドがあり、それぞれが select2 および jquery sortable で動作します。

実際、各フィールドにソート可能な機能を持たせるために、各フィールドのコードを複製しましたが、うまく機能します。しかし、おわかりのように、N フィールドで使用するように最適化します。

私のコード:

    // Sortable
    jQuery("#_posts_1").select2("container").find("ul.select2-choices").sortable({
        containment: "parent", 
        start: function() { jQuery("#_posts_1").select2("onSortStart"); },  
        update: function() { jQuery("#_posts_1").select2("onSortEnd"); } });
    jQuery("#_posts_1").on("change", function() { jQuery("#_posts_1").html(jQuery("#_posts_1").val());});

    [... the same code for each field ...]

    jQuery("#_posts_10").select2("container").find("ul.select2-choices").sortable({
        containment: "parent", 
        start: function() { jQuery("#_posts_10").select2("onSortStart"); }, 
        update: function() { jQuery("#_posts_10").select2("onSortEnd"); } });
    jQuery("#_posts_10").on("change", function() { jQuery("#_posts_10").html(jQuery("#_posts_10").val());});

固有の機能を最適化するにはどうすればよいですか? ありがとう

4

1 に答える 1