In diesem Artikel wird die Methode von JS beschrieben, um die Tischreihen auf und ab zu implementieren. Teilen Sie es für Ihre Referenz wie folgt weiter:
<! DocType html public "-// w3c // dtd xhtml 1.0 transitional // en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transsitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>Table row movement</title></head><body><table> <tbody> <tr> <td>1</td> <td> 11 </td> <td> <a href = "javaScript: void (0)" Onclick = "MoveUp (this)"> MOVET </a> </td> <td> <a href = "javascript: void (0)" onclick = "bewegt (tttra) (tttra). <td> 22 </td> <td> <a href = "javaScript: void (0)" Onclick = "MoveUp (this)"> MOVET </a> </td> <td> <a href = "javascript: void (0)" onclick = "bewegt (tht> <td> </td> </td> </td>; <td>33</td> <td><a href="javascript:void(0)" onclick="moveUp(this)">Move up</a></td> <td><a href="javascript:void(0)" onclick="moveDown(this)">Move down</a></td> </tr> <tr> <td>4</td> <td> 44 </td> <td> <a href = "javaScript: void (0)" Onclick = "MoveUp (this)"> Move up </a> </td> <td> <a href = "javaScript: void (0)" Onclick = "bewegt (thly)"> ">"> ">"> "> Move"> ">"> ">"> ">"> ">"> ">"> ">"> Move </td> </td> </td> </td> </td> </td> </td> </td> </td> </td> </td> </td> </td> </td> </td> </td> </td> </td> </td> </td> </td> </td> </td> </td> </td> </td> </td> </td>; <td> 55 </td> <td> <a href = "javaScript: void (0)" Onclick = "MoveUp (this)"> MOVET </a> </td> <td> <a href = "javascript: void (0)" onclick = "bewegt (). type = "text/javaScript"> <!-Funktion moveUp (_a) {var _row = _a.parentnode.parentnode; // Wenn es nicht die erste Zeile ist, tauschen Sie die Reihenfolge mit der vorherigen Zeile var _node = _row.previoussibling aus; while (_node && _node.nodetype! = 1) {_node = _node.previoussibling; } if (_node) {swapNode (_row, _node); }} Funktion bewegt (_a) {var _row = _a.parentnode.parentnode; // Wenn es nicht die letzte Zeile ist, tauschen Sie die Reihenfolge mit der nächsten Zeile var _node = _row.nextsibling aus; while (_node && _node.nodeType! = 1) {_node = _node.nextSsibling; } if (_node) {swapNode (_row, _node); }} Funktion SWAPNODE (NODE1, NODE2) {// Den übergeordneten Knoten var _parent = node1.parentnode abrufen; // Erhalten Sie die relative Position der beiden Knoten var _t1 = node1.Nextsibling; var _t2 = node2.nextsibling; // NODE2 in die ursprüngliche Knotenposition einfügen if (_t1) _parent.insertbefore (node2, _t1); sonst _parent.AppendChild (Node2); // Node1 in die ursprüngliche NODE2 -Position einfügen if (_t2) _parent.insertbefore (node1, _t2); sonst _parent.Appendchild (node1);} //-> </script> </body> </html>Der Screenshot des Laufeffekts lautet wie folgt:
For more information about JavaScript related content, please check out the topics of this site: "Summary of JavaScript Search Algorithm Skills", "Summary of JavaScript Data Structure and Algorithm Skills", "Summary of JavaScript traversal algorithms and techniques", "Summary of json operation techniques in JavaScript", "Summary of JavaScript switching effects and techniques", "Summary of JavaScript -Animationseffekte und -techniken "," Zusammenfassung der JavaScript -Fehler und Debugging -Techniken "und" Zusammenfassung der Nutzung von JavaScript -Mathematikoperationen ""
Ich hoffe, dieser Artikel wird für JavaScript -Programme aller hilfreich sein.