js、javascript去掉前后空格

function String.prototype.Trim() { return this.replace(/(^/s*)|(/s*$)/g, ""); }   // 去掉左右空格

function String.prototype.Ltrim() { return this.replace(/(^/s*)/g, ""); }            // 去掉左空格

function String.prototype.Rtrim() { return this.replace(/(/s*$)/g, ""); }            // 去掉右空格

<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.9958.pw/post/js_trim

猜你喜欢

转载自ldl-xz.iteye.com/blog/2284712
今日推荐