1: 过滤首尾空格trim、2:过滤左边空格ltrim 3:过滤右边空格
一:用正则方法写成三个函数.
<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>
原文:http://www.cnblogs.com/ChineseMoonGod/p/5077640.html