jQuery parent.sibling logic
jQuery parent.sibling logic
我正在尝试单击一个项目,并让该项目跳转到下一列。 截至目前,当我单击该项目时,该项目会溢出到每隔一列。
这是代码。
我尝试仅将项目移动到下一列,然后移动到下一列。
'use strict';
$(document).ready(init);
function init(){
$('#groupOne').on('click', '.item', clickHolder);
$('#groupOne').on('click', '.item', clickCup);
}
function clickHolder(event){
$('.selected').appendTo($(this));
$('.selected').removeClass('.selected');
}
function clickCup(){
var $this = $(this);
$this.addClass('.selected');
var $sibling = $this.parents().siblings();
var $detached = $this.detach();
$sibling.append($detached);
}
<div class="topRow">
<input type="text">
<input type="number">
<button>Add</button>
</div>
<table id="groupOne">
<tr>
<th>Item</th>
<th>Price</th>
</tr>
<tr class="item">
<td>Banana</td>
<td>14.99</td>
</tr>
<tr class="item">
<td>Apple</td>
<td>5.99</td>
</tr>
<tr class="item">
<td>Tomato</td>
<td>8.99</td>
</tr>
</table>
<table id="groupTwo"></table>
<table id="groupThree"></table>
<table id=id="groupFour"></table>
<script src="https://code.jquery.com/jquery-2.2.1.min.js"></script>
<script src="main.js"></script>
我像这样修复它。不确定你想要什么,但这可能是一个线索?
$(".item").click(function() {
$(this).parents("table").append($(this));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="topRow">
<input type="text">
<input type="number">
<button>Add</button>
</div>
<table id="groupOne">
<tr>
<th>Item</th>
<th>Price</th>
</tr>
<tr class="item">
<td>Banana</td>
<td>14.99</td>
</tr>
<tr class="item">
<td>Apple</td>
<td>5.99</td>
</tr>
<tr class="item">
<td>Tomato</td>
<td>8.99</td>
</tr>
</table>
<table id="groupTwo"></table>
<table id="groupThree"></table>
<table id="groupFour"></table>
这是向上/向下移动项目行onclick
的代码。
'use strict';
$(document).ready(init);
function init(){
$('#groupOne').on('click', '.item', clickCup);
}
function clickCup(){
// Use this to move the row down
$(this).insertAfter($(this).next());
// Use this to move the row down
//$(this).insertBefore($(this).prev());
}
<div class="topRow">
<input type="text">
<input type="number">
<button>Add</button>
</div>
<table id="groupOne">
<thead>
<tr>
<th>Item</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<tr class="item">
<td>Banana</td>
<td>14.99</td>
</tr>
<tr class="item">
<td>Apple</td>
<td>5.99</td>
</tr>
<tr class="item">
<td>Tomato</td>
<td>8.99</td>
</tr>
</tbody>
</table>
<table id="groupTwo"></table>
<table id="groupThree"></table>
<table id=id="groupFour"></table>
<script src="https://code.jquery.com/jquery-2.2.1.min.js"></script>
<script src="main.js"></script>
相关文章:
- jQuery slide sibling element
- jQuery parent.sibling logic
- Javascript Logic In a loop/if statement
- While-Loop Logic JavaScript
- SVG Morph Javascript Logic
- JqueryAjax and php logic
- javascript if if else logic
- slideToggle不能用于.sibling方法
- 将jQuery的parent()和sibling()调用转换为纯Javascript
- jQuery导航-更改input parent-parent-parent-parent-sibling的输入
- jQuery:悬停Div以显示Sibling
- 从parent中移除一个子节点,并将其添加为Sibling到parent
- NodeJS, express and mongoDB - mapping logic
- HTML5 WebWorker Logic flow
- Jquery中,在元素前选择sibling
- 获取sibling - extjs的值