firefox使用技巧(1)——对网页列表排序

firefox使用技巧(1)——对网页列表排序(含视频)

firefox使用技巧(1)——对网页列表排序


0. 前言

网上的信息太多了,有必要对之进行筛选(而非审查)。

作为程序员,既然有工具,为什么不用呢!

如果你有网页编程经验,十有八九听说过firefox/firebug/jQuery了。

如果你还没听说过,了解一下也没坏处。

本视频为了说明一个道理:学以致用

1. jQuery

复制代码
var sortlist = function(list, key, asc){
    asc = typeof asc !== 'undefined' ? asc : true
    $(list).html(function(){
        return $(this).children().sort(function(x, y){
            return [x, y].map(function(e){
                return parseInt($(key, e).text().replace(/[^-+0-9.]/g, ''))
            }).reduce(function(i, j){
                return asc ? i-j : j-i
            })
        })
    })
}

var clicksort = function(btn, list, key){
    $(btn).unbind('click').click(function(){
        var asc = $(this).attr('asc') == 'true' ? true : false
        sortlist(list, key, !asc)
        $(this).attr('asc', !asc)
        return false;
    })
}
复制代码

 

2. Examples

clicksort("#logo img", "#post_list", ".diggnum")

clicksort(".logo img" , "#m13070668983 tbody" , ".pub")

clicksort('#hlogo', '#question-mini-list', '.votes .mini-counts')

clicksort('.contentWrapper', '#leagueUserList', '.number:nth(1)')

3. Screencast

posted @ 2012-05-09 22:54  蛊惑Into  阅读(498)  评论(0编辑  收藏  举报