﻿jQuery.fn.cycle = function(c1, c2, cm){
    if(!(c1 && c2)) return; //判断有没得参数传入
    var css, oj;
    this.each(function(){ //选中了多少个表格
        oj = jQuery("tr",jQuery(this));
        oj.each(function(i){ // 选中表格中的 TR 加 CSS
            css = i % 2 == 0 ? c1 : c2;
            jQuery(this).addClass(css);
        });
        
        if(cm){ //如果有第三个参数
            oj.hover(function(){
                jQuery(this).addClass(cm);
            },
            function(){
                jQuery(this).removeClass(cm);
            });
        }
    });
} 

