trim()可以这样实现:String.prototype.trim=function(){
return this.replace(/(^\s*)|(\s*$)/g,"");
}

解决方案 »

  1.   

    你说的不管用呀,我试了,你能不能换我写的例子给改一下if (  MANALOC.getValue().length == 0 )
    {
         MANALOC.focus() ;
         alert('经营地址不能为空');
       return;
    }
      

  2.   

    楼主请看,要这样用就可以了
    <script language="JavaScript">
    <!--
    String.prototype.trim=function(){
    return this.replace(/(^\s*)|(\s*$)/g,"");
    }
    alert(" df dfd  ".trim().length)
    //-->
    </script>
      

  3.   

    var reSpaceCheck = /^\s*$/; //'判断空格
    if (reSpaceCheck.test(myform.hm.value)) {
      alert("核销号码不能为空!");
      myform.hm.focus();
      return false;
    }
      

  4.   

    //字符串去除两端空字符
    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, "");}