美文网首页
js实用函数集;

js实用函数集;

作者: ft207741 | 来源:发表于2018-10-20 06:44 被阅读0次

    Menu

    • str.format()

    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
    

    相关文章

      网友评论

          本文标题:js实用函数集;

          本文链接:https://www.haomeiwen.com/subject/ngnvaftx.html