解决方案 »
- 求js实现快速排序算法
- document.frames["MyIFrame"].document为什么不能用呢
- 为什么要加入这样一句话就可以?
- jquery或js怎样让第一个ifame中的bottun来控制第二个iframe的src?
- 很简单的`帮帮忙`教一教``关于JS翻页
- js 的全选,不可以使用NAME 属性
- 我下载了个DHTML Tooltips工具栏提示JS源码 可使用时老弹出版权提示框
- java中如何调用系统的计算器程序
- 这段JS代码怎么出问题了?不运行
- 怎么才能用JS插入背景音乐呢?
- 如果用js获取regularexpressionvalidator验证结果
- 有关div里面的img旋转角度问题
http://james.padolsey.com/javascript/sorting-elements-with-jquery/
需要jquery,这是我在用的一个/**
* jQuery.fn.sortElements
* --------------
* @param Function comparator:
* Exactly the same behaviour as [1,2,3].sort(comparator)
*
* @param Function getSortable
* A function that should return the element that is
* to be sorted. The comparator will run on the
* current collection, but you may want the actual
* resulting sort to occur on a parent or another
* associated element.
*
* E.g. $('td').sortElements(comparator, function(){
* return this.parentNode;
* })
*
* The <td>'s parent (<tr>) will be sorted instead
* of the <td> itself.
*/
jQuery.fn.sortElements = (function(){
var sort = [].sort;
return function(comparator, getSortable) {
getSortable = getSortable || function(){return this;};
var placements = this.map(function(){
var sortElement = getSortable.call(this),
parentNode = sortElement.parentNode,
// Since the element itself will change position, we have
// to have some way of storing its original position in
// the DOM. The easiest way is to have a 'flag' node:
nextSibling = parentNode.insertBefore(
document.createTextNode(''),
sortElement.nextSibling
);
return function() {
if (parentNode === this) {
throw new Error(
"You can't sort elements if any one is a descendant of another."
);
}
// Insert before flag:
parentNode.insertBefore(this, nextSibling);
// Remove flag:
parentNode.removeChild(nextSibling);
};
});
return sort.call(this, comparator).each(function(i){
placements[i].call(getSortable.call(this));
});
};
})();
用法可以这样var numeric = $(this).hasClass('sort_number');
if (numeric) {
$('.film_list_block:eq('+parent_index+') .list').sortElements(function(a, b){
return parseInt($(a).find('div:eq('+index+')').text()) > parseInt($(b).find('div:eq('+index+')').text()) ? 1*order : -1*order;
});
}else {
$('.film_list_block:eq('+parent_index+') .list').sortElements(function(a, b){
return $(a).find('div:eq('+index+')').text().toLowerCase() > $(b).find('div:eq('+index+')').text().toLowerCase() ? 1*order : -1*order;
});
}
你能帮我套用到我的html吗