<head><title>Reverse</title></head> <script> function reverse(n) { // Reverse the order of the children of Node n var kids = n.childNodes; // Get the list of children var numkids = kids.length; // Figure out how many there are for(var i = numkids-1; i >= 0; i--) { // Loop through them backwards var c = n.removeChild(kids[i]); // Remove a child n.appendChild(c); // Put it back at its new position } } </script> </head> <body> <div> <p>paragraph #1<p>paragraph #2<p>paragraph #3 <!-- A sample document --> <p> </div> <!-- A button to call reverse()--> <button onclick="reverse(document.getElementsByTagName('div'));" >Click Me to Reverse</button> </body>楼上的,帮我看看这段代码,运行不了
<button onclick="reverse(document.getElementsByTagName('div'));" >Click Me to Reverse</button> </body>改成 <button onclick="reverse(document.getElementsByTagName('div')[0]);" >Click Me to Reverse</button> </body>
IE6下通过,你用的什么浏览器? <head><title>Reverse</title></head> <script> function reverse(n) { // Reverse the order of the children of Node n var kids = n.childNodes; // Get the list of children var numkids = kids.length; // Figure out how many there are for(var i = numkids-1; i >= 0; i--) { // Loop through them backwards var c = n.removeChild(kids[i]); // Remove a child n.appendChild(c); // Put it back at its new position } } </script> </head> <body> <div> <p>paragraph #1<p>paragraph #2<p>paragraph #3 <!-- A sample document --> <p> </div> <!-- A button to call reverse()--> <button onclick="reverse(document.getElementsByTagName('div')[0]);" >Click Me to Reverse</button> </body>
<script>
function reverse(n) { // Reverse the order of the children of Node n
var kids = n.childNodes; // Get the list of children
var numkids = kids.length; // Figure out how many there are
for(var i = numkids-1; i >= 0; i--) { // Loop through them backwards
var c = n.removeChild(kids[i]); // Remove a child
n.appendChild(c); // Put it back at its new position
}
}
</script>
</head>
<body>
<div>
<p>paragraph #1<p>paragraph #2<p>paragraph #3 <!-- A sample document -->
<p>
</div> <!-- A button to call reverse()-->
<button onclick="reverse(document.getElementsByTagName('div'));"
>Click Me to Reverse</button>
</body>楼上的,帮我看看这段代码,运行不了
>Click Me to Reverse</button>
</body>改成
<button onclick="reverse(document.getElementsByTagName('div')[0]);"
>Click Me to Reverse</button>
</body>
<head><title>Reverse</title></head>
<script>
function reverse(n) { // Reverse the order of the children of Node n
var kids = n.childNodes; // Get the list of children
var numkids = kids.length; // Figure out how many there are
for(var i = numkids-1; i >= 0; i--) { // Loop through them backwards
var c = n.removeChild(kids[i]); // Remove a child
n.appendChild(c); // Put it back at its new position
}
}
</script>
</head>
<body>
<div>
<p>paragraph #1<p>paragraph #2<p>paragraph #3 <!-- A sample document -->
<p>
</div> <!-- A button to call reverse()-->
<button onclick="reverse(document.getElementsByTagName('div')[0]);"
>Click Me to Reverse</button>
</body>