<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang='ru-RU'>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
var $A = function(iterable) {
if (iterable) {
var result = [], i = iterable.length;
while (i) result[--i] = iterable[i];
return result;
}
return [];
};
function parse(sortWhat,width,what) {
var ul = document.getElementById(sortWhat).getElementsByTagName('ul')[0],
arr = $A(ul.getElementsByTagName('li'));
var size = arr.length/width;
var newArr = new Array (size);
for (var i = 0; i<size; i++) {
newArr[i] = new Array(width);
}
for (var i = 0; i<size; i++) {
for (var j = 0; j<width; j++) {
newArr[i][j] = arr[i*width+j];
}
}
newArr.sort(function(i, ii) {
i = i[what].innerHTML.toLowerCase();
ii = ii[what].innerHTML.toLowerCase();
if (i > ii)
return 1;
else if (i < ii)
return -1;
else
return 0;
});
for (var i = 0; i<size; i++) {
for (var j = 0; j<width; j++) {
ul.appendChild(newArr[i][j]);
}
}
return false;
}
</head>
<body>
<input type="button" value="Сортировать(возрастани е)" onclick="parse('sort',4,0);" />
<input type="button" value="Сортировать(возрастани е)" onclick="parse('sort',4,1);" />
<input type="button" value="Сортировать(возрастани е)" onclick="parse('sort',4,2);" />
<input type="button" value="Сортировать(возрастани е)" onclick="parse('sort',4,3);" />
<div id="sort">
<ul>
<li>Л</li>
<li>34</li>
<li>200 </li>
<li>1111f</li>
<li>К</li>
<li>10</li>
<li>10 </li>
<li>3333f</li>
<li>П</li>
<li>23</li>
<li>300 </li>
<li>2222f</li>
</ul>
</div>
</body>
</html>