//更换两个元素的位置 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]