js实用函数集;

2018-10-20  本文已影响0人  ft207741

Menu


str.format()
    String.prototype.format = function () {
        var values = arguments;
        return this.replace(/\{(\d+)\}/g, function (match, index) {
            if (values.length > index) {
                return values[index];
            } else {
                return "";
            }
        });
    };

    var str ='这是一个测试的字符串:{0} {1}'.format('Hello','world');
    document.write(str)  // 这是一个测试的字符串:Hello world
上一篇下一篇

猜你喜欢

热点阅读