现在的位置: 首页 > 综合 > 正文

JavaScript去除空格的三种方法 (trim)

2013年06月11日 ⁄ 综合 ⁄ 共 285字 ⁄ 字号 评论关闭
<SCRIPT LANGUAGE="JavaScript">
<!--
// Trim() , Ltrim() , RTrim()

 

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, ""); 
} 
 
//-->
</SCRIPT>

抱歉!评论已关闭.