// 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, "");
}
使用:x = "  d  "
alert(x.Trim())

解决方案 »

  1.   

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

  2.   

    function trim(strValue)
    {
        if(strValue==null || strValue.length == 0) return ("");
        var cr=String.fromCharCode(13);
        var oldstr="";    while (oldstr.length!=strValue.length)
        {
            oldstr = strValue;
            strValue=b_trim(strValue," ");
            strValue=b_trim(strValue," ");
            strValue=b_trim(strValue,cr);
        }
        return strValue;
    }
      

  3.   

    whnnet(赚钱攒嫁妆)MM写的非常好…………
      

  4.   

    String.prototype.trim() = function()
    {
       return this.replace(/(^\s*)|(\s*$)/g);
    }