对一组div排序
通过对div对象数据按值或其它方式进行排序
<div name="ddd" id="c1">1</div><div name="ddd" id="c2">2</div><div name="ddd" id="c3">3</div><div name="ddd" id="c4">4</div><input type="button" value="test12" οnclick="sortDiv3()"/><script type="text/javascript"><!-- var $ = function(){ return document.getElementById(arguments[0]); } var insertBefore = function(baseO, beforeO){ baseO.parentNode.insertBefore(beforeO, baseO); } function sortDiv(){ var i = arguments.length; while(i-->1){ //alert(i); insertBefore($("c" + arguments[i]), $("c"+ arguments[i-1])); } } //按值倒序排序 function sortDiv3(){ for (i = 1; i < 5; i++) { for (j = i; j < 5; j++) { if ($("c"+i).innerText <$("c"+j).innerText) { insertBefore($("c"+i),$("c"+j)); } } } } //--></script>