本文介绍了上下移动表格行 - Jquery / Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以告诉我如何通过jquery / javascript上下移动表格行。我有一张表格,每行有一个单选按钮第一个td。点击向上/向下箭头,所选行应向上/向下移动。
展望一些想法......
解决方案
首先获取选定的行:
var radio;
//假设页面中只有一种形式,将0替换为
//并且输入名称为'radioGroupName'
(document.forms [0]中的var i)。 radioGroupName){
if(documents.forms [0] .radioGroupName [i] .checked){
radio = documents.forms [0] .radioGroupName [i] .parentNode.parentNode;
休息;
$ / code $ / pre
$ b $ 要上移:
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);
Can anyone please tell me how to move table rows up and down through jquery/javascript.
I have a table and for each row a radio button is there in the first td. Onclicking the up/down arrows the selected rows should move up/down.
Looking forward for some ideas...
解决方案 First get the selected row:
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;
}
}
To shift up:
var prev = radio.previousSibling;
var par = radio.parentNode;
if (prev) {
par.removeChild(radio);
par.insertBefore(radio, prev);
}
To shift down:
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!