我有一個JS事件綁UPARROW: 如何在第一次發生具有已知類名的特定行之後/之前移動行?
$('body').on('click', '.UpArrow', function(event) {
\t \t var row = $(this).closest('tr');
row.insertBefore(row.prev());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<tr class="placeholderRow NameServiceRow">
<td class="UpArrow"></td>
<td class="DownArrow"></td>
<td><input value="2" class="ref" name="ref2" readonly="" type="text"></td>
</tr>
<tr class="placeholderRow inlineService">
<td class="UpArrow"></td>
<td class="DownArrow"></td>
<td><input value="2" class="ref" name="ref2" readonly="" type="text"></td>
</tr>
<tr class="placeholderRow inlineService">
<td class="UpArrow"></td>
<td class="DownArrow"></td>
<td><input value="2" class="ref" name="ref2" readonly="" type="text"></td>
</tr>
<tr class="placeholderRow">
<td class="UpArrow"></td>
<td class="DownArrow"></td>
<td><input value="2" class="ref" name="ref2" readonly="" type="text"></td>
</tr>
我想要做的是移動TR與類名TR NameServiceRow
我已經嘗試了一些解決方案,但沒有以上他們爲我工作,如果你有任何解決方案,我都耳熟能詳。
編輯:
我可能與類名多行NameServiceRow
所以我要的是將它移到這個類名
你的代碼似乎適用於我。當我點擊'UpArrow'時,它將tr移動到prev –
以上我希望它在類名「NameServiceRow」之上移動,而不僅僅是在perv之上 – samouray
嘗試像'row.insertBefore(row.prevAll(「。NameServiceRow」) );' –