其思想是将特定的表行移动到不同的位置
超文本标记语言
<table id="grid1" class="table table-zebra">
<tbody>
<tr>
<td>Cont 1 tr 1</td>
</tr>
<tr>
<td>Cont 2 tr 2</td>
</tr>
<tr>
<td>Cont 3 tr 3</td>
</tr>
<tr>
<td>Cont 4 tr 4</td>
</tr>
<tr>
<td>Cont 5 tr 5</td>
</tr>
<tr>
<td>Cont 6 tr 6</td>
</tr>
<tr>
<td>Cont 6 tr 6</td>
</tr>
<tr>
<td>Cont 7 tr 7</td>
</tr>
<tr>
<td>Cont 8 tr 8</td>
</tr>
<tr>
<td>Cont 9 tr 9</td>
</tr>
<tr>
<td>Cont 10 tr 10</td>
</tr>
<tr>
<td>Cont 11 tr 11</td>
</tr>
<tr>
<td>Cont 12 tr 12</td>
</tr>
<tr>
<td>Cont 13 tr 13</td>
</tr>
<tr>
<td>Cont 14 tr 14</td>
</tr>
</tbody>
</table>
这是基本的表,现在,我怎么才能移动TR 11在一个远离,它将在TR 4下,我很抱歉,我不张贴任何JS,但我不知道如何做到这一点...我正在看这个JSbin这是很好的,但不能使用它...
4条答案
按热度按时间roqulrg31#
将第11个tr移动到第4个tr之下:
Working demo
如果你喜欢香草味的,你需要选择器反过来。
ep6jt1vc2#
在包含如下所示行的HTML表格的上下文中:
这个脚本:
$('. up,. down').单击(函数(){
选择类为“up”的每个DOM元素和类为“down”的每个元素,例如
$('.up,.down').click(function () {
。该函数为每个元素设置一个单击处理程序。变量行= $(this).父对象('tr:first');
$(this)
引用作为单击处理程序的目标的DOM元素(上面选择的“up”或“down”元素之一)。.parents()
查找tr:first
,即第一个<tr>
元素,它从<a>
开始,沿着DOM向上移动。它将最终选择整行。如果($(this).is('. up')){
这是检查所选元素是否具有类“up”。
插入前一行();
这将获取被单击的行,并将其移动到被单击行的最上面的同级行的正上方。
使用的jQuery方法(insertBefore、prev、is、parents等)在jQuery documentation中有更详细的描述。
3yhwsihp3#
您可以使用JQuery库来实现这一点。
uubf1zoe4#
为了动态地移动你的元素,你可以给所有tbody子元素添加一个事件。我基本上是在第一次点击时选择一个元素,然后在第二次点击后移动它。
它移动后的一个元素,但只是一个想法,你可以自定义它.
你的html应该是这样的。