1、清除左空格/右空格
- function ltrim(s){ return s.replace( /^(\s*|*)/, ""); }
- function rtrim(s){ return s.replace( /(\s*|*)$/, ""); }
2、判断是否以某个字符串开头
- String.prototype.startWith = function (s) {
- return this.indexOf(s) == 0
- }
3、判断是否以某个字符串结束
- String.prototype.endWith = function (s) {
- var d = this.length - s.length;
- return (d >= 0 && this.lastIndexOf(s) == d)
- }
来源: http://www.phpxs.com/code/1003796/