-3

各行にチェックボックスが入力されたテーブルがあります。href="#" class="up" または href="#" class="down" がクリックされたとき (行を上に移動するか、下)。

要約すると、テーブル全体で「チェックボックス入力」のdom要素「値」を呼び出す方法を知りたいです。

テーブル:

            <table>
            //first row
            <tr>
            <td><a href="/ezmapping/layer/edit/1">ra_general.shp, burton449</a></td>
            <td><label for="id_layers_0"><input checked="checked" type="checkbox" id="id_layers_0" value="1" name="layers"/></label></td>
            <td><a href="/ezmapping/map/super/LayerStyle/1">Style</a></td>
            <td>
                <a href="#" class="up"><img src="/static/main/img/arrow_up.png"></a>
                <a href="#" class="down"><img src="/static/main/img/arrow_down.png"></a>
            </td>
            </tr>
            .
            .
            .
            </table>

jquery (行を上下に移動する)

  $(document).ready(function(){
      $(".up,.down").click(function(){
          var row = $(this).parents("tr:first");
          if ($(this).is(".up")) {
              row.insertBefore(row.prev());
          } else {
              row.insertAfter(row.next());
          }
      });
  });
4

2 に答える 2

1
var checks = new Array();
$(this).parents("table").find("input:checkbox").each(function() {
  checks.push($(this).is(":checked"));
});

これにより、すべてのチェックボックスの値が配列に収集されます。再注文の前後に配置できます。

JSFiddleデモ

于 2013-08-13T17:02:01.027 に答える