代码如下:
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 language=javascript
String.prototype.Trim = function()
{
return this.replace(/(^s*)|(s*$)/g, "");
}
var s = " leading and trailing spaces ";
window.alert(s + " (" + s.length + ")");
s = s.Trim();
window.alert(s + " (" + s.length + ")");
/script 猜你喜欢