获得文本框的文本  里面带有空格 有没有那个函数可以清除 。Trim()不让用#24   来个方便的

解决方案 »

  1.   

    <script>
    String.prototype.trim   =   function()
    {return   this.replace(/(^\s*)|(\s*$)/g,   "");}
    alert('   sd f  '.trim().length+'   value为'+'   sd f  '.trim())
    </script>
      

  2.   


    <script language="javascript">
    var str=" 中  华 全  国 工 商 联合 会 ";
    str=str.replace(/ /g,"");  //清除所有的半角空格.
    str=str.replace(/ /g,"");  //清除所有的全角空格.
    document.write(str);
    </script>
      

  3.   

    String.prototype.trim   =   function()
    {return   this.replace(/\s/g,   "");}
    alert(' 1 2   3  '.trim())