封裝 js 插件 實例

jqueryTools.jshtml

(function($){jquery

/*

format text string leave you want len ,can also use fix string and fixLen set

 $.formatText("abcdefghi",5,{fix:".",fixLen:3}) ==> "abcde..."   #html文件使用格式

 */

$.formatText = function(text, len, settings){

    var sets = $.extend({

        "fix":null,

        'fixLen':null

    },settings||{});

    if (len){

        var gap = text.length - len;

        var newText = "";

        if (gap > 0){

            newText = text.substring(0,len);

            if (sets.fix && sets.fixLen){

                for (var i=0;i<sets.fixLen;i++){

                    newText +=sets.fix;

                }

            }

            return newText;

        }

    }

};

})(jQuery);code

相關文章
相關標籤/搜索