js让<li>以倒叙排序?

JavaScript019

js让<li>以倒叙排序?,第1张

<div class="a"><ul class="b"><li>1</li><li>2</li><li>3</li></ul></div>

<script>

window.onload=function(){

var ul=document.getElementsByClassName("b")[0]

var lis=ul.getElementsByTagName("li")

for(var i=lis.length-1i>=0i--){

ul.appendChild(lis[i])

}

}

</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/htmlcharset=utf-8" />

<style type="text/css">

body{

font-size:12px

color:#663300

}

</style>

<META NAME="Generator" CONTENT="EditPlus">

<META NAME="Author" CONTENT="Quan Wen">

<META NAME="Keywords" CONTENT="">

<META NAME="Description" CONTENT="">

<SCRIPT Language="Javascript">

function do_change()

{

var str = document.myform.mytext.value

var len = document.myform.mytext.value.length

var i

var mystr = ""

for (i=len-1i>=0i--)

{

mystr += str.charAt(i)

}

document.myform.changetext.value = mystr

}

</SCRIPT>

</HEAD>

<BODY>

<FORM name="myform" action="a.html" method="POST">

<TABLE border="0">

<TR>

<TD>

你的输入:

</TD>

<TD>

倒序输出:

</TD>

</TR>

<TR>

<TD>

<TEXTAREA type="text" name="mytext"></TEXTAREA>

</TD>

<TD>

<TEXTAREA type="text" name="changetext" disabled></TEXTAREA>

</TD>

</TR>

<TR>

<TD colspan="2">

<INPUT type="button" onClick="do_change()" name="Change" value="倒序输出">

</TD>

</TR>

</TABLE>

</FORM>

</BODY>

</HTML>