为了对结果进行排序,我使用下面的代码在javascript中交换两个结果数组。但它不能在firefox和chrome浏览器中工作,但只能在IE中工作。
for (x=0; x<resultArr.length; x++) {
allTR[x].swapNode(colArr[resultArr[x]])
}
如果不使用swapNode函数,如何交换两个数组。这里的allTR既是我的父数组,也是目标数组。不管我有什么临时变量,最后我都应该把它附加到allTR数组中。请帮我解决这个问题
发布于 2018-06-08 04:25:52
这在标准JavaScript中非常简单:
假设您想交换两个兄弟a
和b
,那么代码将如下所示:
a.parentNode.insertBefore(b,a)
在本例中,代码将是allTR[x].parentnode.insertBefore(colArr[resultArr[x]],allTR[x])
发布于 2021-05-20 14:06:20
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());
}
}
});
});
});
https://stackoverflow.com/questions/28612188
复制相似问题