首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >javascript swapNode在firefox和chrome中不起作用。

javascript swapNode在firefox和chrome中不起作用。
EN

Stack Overflow用户
提问于 2015-02-20 00:54:12
回答 2查看 877关注 0票数 1

为了对结果进行排序,我使用下面的代码在javascript中交换两个结果数组。但它不能在firefox和chrome浏览器中工作,但只能在IE中工作。

代码语言:javascript
复制
for (x=0; x<resultArr.length; x++) {    
        allTR[x].swapNode(colArr[resultArr[x]])
    }

如果不使用swapNode函数,如何交换两个数组。这里的allTR既是我的父数组,也是目标数组。不管我有什么临时变量,最后我都应该把它附加到allTR数组中。请帮我解决这个问题

EN

回答 2

Stack Overflow用户

发布于 2018-06-08 04:25:52

这在标准JavaScript中非常简单:

假设您想交换两个兄弟ab,那么代码将如下所示:

a.parentNode.insertBefore(b,a)

在本例中,代码将是allTR[x].parentnode.insertBefore(colArr[resultArr[x]],allTR[x])

票数 1
EN

Stack Overflow用户

发布于 2021-05-20 14:06:20

代码语言:javascript
复制
For **java Script** the solution is for swapping item(row to be moved),previous 
**MoveUp** :
document.getElementById("item").parentNode.insertBefore(document.getElementById("item"),document.getElementById("previous"));

**MoveDown**: 

document.getElementById("item").parentNode.insertBefore(document.getElementById("next"),document.getElementById("item"));

**Jquery:
MoveUp:**

$(function(){
$("upRowId").click(function(event){
var itemRow="";
button_choice=$(this).attr('id');
$(":radio").each(function(){
if(this.checked){
itemRow=$this.closest('tr');
if(button_choice=="upRowId"){
itemRow.insertBefore(itemRow.prev());
    }
   }
  });
 });
});

**MoveDown:**

$(function(){
$("downRowId").click(function(event){
var itemRow="";
button_choice=$(this).attr('id');
$(":radio").each(function(){if(this.checked){
itemRow=$this.closest('tr');
if(button_choice=="downRowId"){
itemRow.insertAfter(itemRow.next());
}
}
});
});
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28612188

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档