在js 文件中写一个函数

String.prototype.format = function(args) {
var result = this;
if (arguments.length > 0) {
if (arguments.length == 1 && typeof (args) == "object") {
for (var key in args) {
if(args[key]!=undefined){
var reg = new RegExp("({" + key + "})", "g");
result = result.replace(reg, args[key]);
}
}
}
else {
for (var i = 0; i < arguments.length; i++) {
if (arguments[i] != undefined) {
var reg= new RegExp("({)" + i + "(})", "g");
result = result.replace(reg, arguments[i]);
}
}
}
}
return result;
}
s='我的名字是{0},家是{1}'.format('于洋','济南');
console.log(s);
测试,OK

取富文本编辑框的文本内容

最新文章

  1. python MethodType方法详解和使用
  2. 攻城狮在路上(伍)How tomcat works(四)Tomcat的默认连接器
  3. Volley(五)—— 自定义Request
  4. RM报表里的变量
  5. 服务器的Arch Linux,CentOS的,Debian的,Fedora的,Gentoo的,openSUSE的,Slackware的,和Ubuntu哪个好
  6. poj 3660 Cow Contest(传递闭包 Floyd)
  7. Quartz动态配置表达的方法
  8. IOS开发之KVC与KVO简述
  9. Html 中select标签的边框与右侧倒三角的去除
  10. Tree( 树) 组件[2]
  11. [T]各种字符串Hash函数比较
  12. MySQL数据库中日期中包涵零值的问题
  13. 分享:苹果APP更新上架被拒的另一种理由(Safety - Objectionable Content)
  14. c语言贪吃蛇详解1.画出地图
  15. centos7.2中文乱码解决办法
  16. 详解EBS接口开发之供应商导入(补充)--错误信息处理
  17. Ansible-基础
  18. [Swift]LeetCode74. 搜索二维矩阵 | Search a 2D Matrix
  19. js和jQuery的互相转换
  20. PAT甲题题解-1062. Talent and Virtue (25)-排序水题

热门文章

  1. TeamWork#1,Week 2,Learn In Team
  2. linux下创建virtualenv时指定python版本
  3. 福大软工1816 &#183; 评分结果 &#183; Alpha冲刺
  4. 1001.A+B Format (20)的感受
  5. week4b:个人博客作业
  6. java、maven环境搭建
  7. PHP 官方发行版扩展下载地址
  8. httpstat的简单使用
  9. C#实体对象序列化成Json,并让字段的首字母小写
  10. sql中的duplicate的使用