ここに示すコードを使用して、jquery を使用してグリッドビューで行を上下に移動しましたが、これは完全に機能しますが、行をテーブルの最初の位置または最後に移動するにはどうすれば実装できますか?
17659 次
3 に答える
17
上と下のリンクを追加し、最初/最後の行の後/前に挿入します。
デモ
JS:
$(document).ready(function(){
$(".up,.down,.top,.bottom").click(function(){
var row = $(this).parents("tr:first");
if ($(this).is(".up")) {
row.insertBefore(row.prev());
} else if ($(this).is(".down")) {
row.insertAfter(row.next());
} else if ($(this).is(".top")) {
row.insertBefore($("table tr:first"));
}else {
row.insertAfter($("table tr:last"));
}
});
});
HTML:
<table>
<tr>
<td>One</td>
<td>
<a href="#" class="up">Up</a>
<a href="#" class="down">Down</a>
<a href="#" class="top">Top</a>
<a href="#" class="bottom">Bottom</a>
</td>
</tr>
<tr>
<td>Two</td>
<td>
<a href="#" class="up">Up</a>
<a href="#" class="down">Down</a>
<a href="#" class="top">Top</a>
<a href="#" class="bottom">Bottom</a>
</td>
</tr>
<tr>
<td>Three</td>
<td>
<a href="#" class="up">Up</a>
<a href="#" class="down">Down</a>
<a href="#" class="top">Top</a>
<a href="#" class="bottom">Bottom</a>
</td>
</tr>
<tr>
<td>Four</td>
<td>
<a href="#" class="up">Up</a>
<a href="#" class="down">Down</a>
<a href="#" class="top">Top</a>
<a href="#" class="bottom">Bottom</a>
</td>
</tr>
<tr>
<td>Five</td>
<td>
<a href="#" class="up">Up</a>
<a href="#" class="down">Down</a>
<a href="#" class="top">Top</a>
<a href="#" class="bottom">Bottom</a>
</td>
</tr>
</table>
于 2013-05-13T14:50:25.690 に答える
1
できるよ
$(document).ready(function(){
$(".first,.last").click(function(){
var row = $(this).parents("tr:first");
var rows= row.parents().find("tr");
if ($(this).is(".first")) {
row.insertBefore(rows[0]);
} else {
row.insertAfter(rows[rows.length]);
}
});
});
于 2013-05-13T14:49:56.687 に答える
0
$(document).ready(function(){
$(".first,.last").click(function(){
var row = $(this).parents("tr:first");
var rows= row.parents().find("tr");
if ($(this).is(".first")) {
row.insertBefore(rows[0]);
} else {
row.insertAfter(rows[rows.length]);
}
});
});
于 2016-08-02T13:37:09.947 に答える