Last active
October 24, 2016 06:25
-
-
Save z007/9c1323a6b3b0b44d51d7ba5eb803f379 to your computer and use it in GitHub Desktop.
JavaScript去除字符串两边空格 两边trim
This file contains hidden or 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
http://www.nowamagic.net/javascript/js_TrimInJavascript.php | |
<script type="text/javascript"> | |
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> | |
删除字符串中所有的空格 | |
str.replace(/\s/g,""); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment