ค่าของการส่งมอบ li.html
การคัดลอกรหัสมีดังนี้:
<! doctype html>
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv = "content-type" content = "text/html; charset = utf-8"/>
<title> สลับค่าของ Li </title>
<script type = "text/javascript">
window.onload = function () {
var lis = document.getElementById ("ULLIST"). ChildNodes;
สำหรับ (var i = 0; i <lis.length; i ++) {
var myli = lis [i];
// ตัดสินว่ามันเป็นแท็กหรือไม่
if (myli.nodeType == 1) {
// สลับตำแหน่งด้วย li ด้านล่าง
myli.onclick = function () {
if (this.nextElementsibling) {
var nextli = this.nextelementsibling; // สิ่งนี้สามารถใช้ได้ที่นี่ไม่ใช่ myli
document.getElementById ("ultist"). แทรกก่อน (nextli, this);
-
-
-
-
-
</script>
</head>
<body>
<ul id = "ullist">
<li> ปักกิ่ง </li>
<li> Shanxi </li>
<li> เซี่ยงไฮ้ </li>
<li> Tianjin </li>
<li> Henan </li>
</ul>
</body>
</html>