Home > Web Front-end > JS Tutorial > body text

$.format,jquery.format usage instructions_jquery

WBOY
Release: 2016-05-16 18:04:39
Original
1198 people have browsed it
复制代码 代码如下:

$.format = function (source, params) {
if (arguments.length == 1)
return function () {
var args = $.makeArray(arguments);
args.unshift(source);
return $.format.apply(this, args);
};
if (arguments.length > 2 && params.constructor != Array) {
params = $.makeArray(arguments).slice(1);
}
if (params.constructor != Array) {
params = [params];
}
$.each(params, function (i, n) {
source = source.replace(new RegExp("\{" i "\}", "g"), n);
});
return source;
};

/*调用方法
var text = "a{0}b{0}c{1}dnqq{0}";
var text2 = $.format(text, 1, 2);
alert(text2);
*/
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template