javascrpt 去掉空格
//去左空格;
function ltrim(s)
{
return s.replace(/(^\s*)/g, "");
}
//去右空格;
function rtrim(s)
{
return s.replace(/(\s*$)/g, "");
}
//去左右空格;
function trim(s)
{
//return s.replace(/(^\s*)|(\s*$)/g, "");
return rtrim(ltrim(s));
}
原型方法:
<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>
<!--
//出处:网上搜集
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>