上下移动表格行 - Jquery/Javascript [英] Move table rows up and down - Jquery/Javascript
本文介绍了上下移动表格行 - Jquery/Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
谁能告诉我如何通过 jQuery/Javascript 上下移动表格行.
Can anyone please tell me how to move table rows up and down through jQuery/Javascript.
我有一张表格,第一个 td 中的每一行都有一个单选按钮.单击向上/向下箭头时,所选行应向上/向下移动.
I have a table and for each row a radio button is there in the first td. On clicking the up/down arrows the selected rows should move up/down.
期待一些想法......
Looking forward for some ideas...
推荐答案
先获取选中的行:
var radio;
// assuming there's only one form in your page, replace 0 with whatever it is
// and inputs have name 'radioGroupName'
for (var i in document.forms[0].radioGroupName) {
if (documents.forms[0].radioGroupName[i].checked) {
radio = documents.forms[0].radioGroupName[i].parentNode.parentNode;
break;
}
}
上移:
var prev = radio.previousSibling;
var par = radio.parentNode;
if (prev) {
par.removeChild(radio);
par.insertBefore(radio, prev);
}
向下移动:
var next = radio.nextSibling;
var par = radio.parentNode;
par.removeChild(radio);
if (next.nextSibling)
par.insertBefore(radio, next.nextSibling);
else
par.appendChild(radio);
这篇关于上下移动表格行 - Jquery/Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文