-
-
Save shingchi/7883167 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script language="javascript"> | |
/* | |
* 写成类的方法格式如下:str.trim() | |
*/ | |
String.prototype.trim=function(){ //删除左右两端的空格 | |
return this.replace(/(^\s*)|(\s*$)/g, ""); | |
} | |
String.prototype.ltrim=function(){ //删除左边的空格 | |
return this.replace(/(^\s*)/g,""); | |
} | |
String.prototype.rtrim=function(){ //删除右边的空格 | |
return this.replace(/(\s*$)/g,""); | |
} | |
/* | |
* 写成函数可以这样:trim(str) | |
*/ | |
function trim(str){ //删除左右两端的空格 | |
return str.replace(/(^\s*)|(\s*$)/g, ""); | |
} | |
function ltrim(str){ //删除左边的空格 | |
return str.replace(/(^\s*)/g,""); | |
} | |
function rtrim(str){ //删除右边的空格 | |
return str.replace(/(\s*$)/g,""); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment