(function($){
    $(document).ready(function(){
        $(".redirect").doRedirect(3);
    });
    /*
     * @example
     * HTML: 3秒后跳转
     * JS:   $(".redirect").doRedirect(3);
	 * 时间顺序为:html > 函数参数 > 默认值3秒
     */
    $.fn.extend({
        doRedirect: function(timeout){
            //避免通用引入时,不存在指定对象也跳转
            if(!$(this).size()) return false;
            var time = $(this).text();
            if(time != '' && !isNaN(time)) {
                timeout = time;
            }
            if(typeof timeout == "undefined") timeout = 3;
            $This   = $(this);
            $.redirectTimer = setInterval(function() {
                timeout--;
                if(timeout == 0) {
                    clearInterval($.redirectTimer);
                    location.href = $This.attr("link");
                } else {            
                    $This.text(timeout);
                }
            }, 1000);
        }
    });
})(jQuery);
演示地址:jQuery自动跳转插件
未经同意禁止转载!
转载请附带本文原文地址:跳秒自动跳转jQuery插件,首发自 Zjmainstay学习笔记

 
  	
    

 
 

