ahomeeye 发表于 2013-2-7 18:51:30

js去除前后空格方法

js去除前后空格方法
//去除前后空格方法String.prototype.trim = function(){      return this.replace(/(^\s*)|(\s*$)/g, "");}//去除前面的空格方法String.prototype.trimLeft = function(){       return this.replace(/(^\s*)/g, "");    }    //去除后面的空格方法String.prototype.trimRight = function(){       return this.replace(/(\s*$)/g, "");    } //表单验证function fastSubmit(f){var form=f;var ra=form.searchType;var radioValue="";for(var i=0;i<ra.length;i++){       if(ra.checked){      radioValue=ra.value;   }}if(radioValue==""){    alert("请选择查询类型!");    return false;    }else if(form.content.value.trim()==""){    alert("请输入内容!");    return false;}}<form action="/fastSearch.action" method="post" id="fastForm" >      <ul>      <li style="padding-left:20px;">          <input type="radio" value="0" name="searchType"/>          PN / FC          <input type="radio" value="1" name="searchType"/>          整机型号          <input type="radio" value="2" name="searchType"/>          整机名称          <input type="text" class="m3" name="content"/>      </li>      <li>          <input type="submit" value="提交"/>      </li>      </ul></form>
参考:
http://blog.stevenlevithan.com/archives/faster-trim-javascript
http://www.iteye.com/topic/1021677
页: [1]
查看完整版本: js去除前后空格方法