Js 更换html同一父元素下子元素的位置

//更换两个元素的位置
                    function exchange(el1, el2) {
                        var ep1 = el1.parentNode,
                            ep2 = el2.parentNode,
                            index1 = Array.prototype.indexOf.call(ep1.children, el1),
                            index2 = Array.prototype.indexOf.call(ep2.children, el2);
                        ep2.insertBefore(el1, ep2.children[index2]);
                        ep1.insertBefore(el2, ep1.children[index1]);
                    }

//注意Jq  $(".class") 获取的是一个数组格式,需传入$(".class")[0]

猜你喜欢

转载自www.cnblogs.com/lbonet/p/11211351.html