读书人

js除了前后空格方法

发布时间: 2012-08-24 10:00:21 作者: rapoo

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[i].checked){        radioValue=ra[i].value;     }  }  if(radioValue==""){    alert("请选择查询类型!");    return false;    }else if(form.content.value.trim()==""){    alert("请输入内容!");    return false;  }}<form action="/fastSearch.action" method="post" id="fastForm" onSubmit="return fastSubmit(this);">      <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" 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

读书人网 >JavaScript

热点推荐