<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="LRSelect.js" type="text/javascript"></script>
<script type="text/javascript">
function test() {
$("#uList").children().reverseSelf().appendTo($("#uList").empty());
//另一种方法:
//取得所有子元素, 再将其转为dom数组, 利用数组反向, 再转为jQuery对象, 再添加到已清空的列表中
$($("#uList").children().get().reverse()).appendTo($("#uList").empty());
}
</script>
</head>
<body>
<ul id="uList" >
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
<input type="button" value="反转列表" style="color:Red;" onclick="test()" />
</body>
</html>
自身列表的反转
最新推荐文章于 2024-04-13 14:15:00 发布