码迷,mamicode.com
首页 > Windows程序 > 详细

JS添加类似C# string.Format方法

时间:2017-06-22 12:13:42      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:net   form   i++   输入   str   exp   ++   string   bsp   

String.prototype.format=function()  
{  
  if(arguments.length==0) return this;  
  for(var s=this, i=0; i<arguments.length; i++)  
    s=s.replace(new RegExp("\\{"+i+"\\}","g"), arguments[i]);  
  return s;  
};  




//占位符可以为多个  
alert("http://{0}/{1}".format("www.songyanjun.net", "index.html"));  
//与上同理  
alert("请输入{0},输完后再按存盘按钮".format("姓名"));  

JS添加类似C# string.Format方法

标签:net   form   i++   输入   str   exp   ++   string   bsp   

原文地址:http://www.cnblogs.com/sunxueyang222/p/7064050.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!