Home > Web Front-end > JS Tutorial > $.format,jquery.format usage instructions_jquery

$.format,jquery.format usage instructions_jquery

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 18:04:39
Original
1254 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:
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
Latest Issues
format
From 1970-01-01 08:00:00
0
0
0
How to format date in JavaScript?
From 1970-01-01 08:00:00
0
0
0
How to format date in JavaScript?
From 1970-01-01 08:00:00
0
0
0
Format date string
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template