首页 > Web开发 > 详细

js 扩展实例

时间:2017-05-08 19:51:43      阅读:265      评论:0      收藏:0      [点我收藏+]

 

 

//扩展实例1 字符串中首字符转大写
var test=‘  this is  ‘;
String.prototype.mytrim=function(){
    var re=/^\s+(.*?)\s+$/;
    return this.replace(re,‘$1‘);
};
console.log(‘[‘+test+‘]‘);
console.log(‘[‘+test.trim()+‘]‘);

//test.mytrim() 等价于:test.replace(re,‘$1‘);
console.log(‘[‘+test.mytrim()+‘]‘);

name = ‘aaa bbb ccc‘;
uw=name.replace(/\b\w+\b/g, function(word){
        console.log(word);
        return word.substring(0,1).toUpperCase()+word.substring(1);}
);

 

js 扩展实例

原文:http://www.cnblogs.com/web-fusheng/p/6826916.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!