<!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/html; charset=utf-8" />
<title>測試test</title>
</head>
<script language="javascript">
</script>
<div id="content">
<div id="cd3">內容3</div>
<div id="cd9">內容9</div>
<div id="cd1">內容1</div>
<div id="cd8">內容8</div>
<div id="cd4">內容4</div>
<div id="cd7">內容7</div>
<div id="cd5">內容5</div>
<div id="cd2">內容2</div>
<div id="cd6">內容6</div>
<div id="cd0">內容0</div>
</div>
<body>
</body>
</html>
想要的效果!!
<div id="content">
<div id="cd0">內容0</div>
<div id="cd1">內容1</div>
<div id="cd2">內容2</div>
<div id="cd3">內容3</div>
<div id="cd4">內容4</div>
<div id="cd5">內容5</div>
<div id="cd6">內容6</div>
<div id="cd7">內容7</div>
<div id="cd8">內容8</div>
<div id="cd9">內容9</div>
</div>
<div id="content">
<div id="cd3">內容3</div>
<div id="cd9">內容9</div>
<div id="cd1">內容1</div>
<div id="cd8">內容8</div>
<div id="cd4">內容4</div>
<div id="cd7">內容7</div>
<div id="cd5">內容5</div>
<div id="cd2">內容2</div>
<div id="cd6">內容6</div>
<div id="cd0">內容0</div>
</div>
<script>
var arrDOM = [], content = document.getElementById('content'), divs = content.getElementsByTagName('div');
for (i = 0; i < divs.length; i++) arrDOM[i] = divs[i];
arrDOM.sort(function (a, b) { return parseInt(/\d+/.exec(a.innerHTML)[0]) - parseInt(/\d+/.exec(b.innerHTML)[0]) });
for (i in arrDOM) content.appendChild(arrDOM[i]);
</script>