html5中文学习网

您的位置: 首页 > 网站及特效实例 > javascript特效 » 正文

js substring从右边获取指定长度字符串(示例代码)_javascript技巧_

[ ] 已经帮助:人解决问题
如下所示:
复制代码 代码如下:

 /*

   Get the rightmost substring, of the specified length,

   from a String object.

*/ 

String.prototype.right = function (length_) 



        var _from = this.length - length_; 

        if (_from < 0) _from = 0; 

        return this.substring(this.length - length_, this.length); 

}; 
(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助