js去除前后空格方法
参考:
[url]http://blog.stevenlevithan.com/archives/faster-trim-javascript[/url]
[url]http://www.iteye.com/topic/1021677[/url]
//去除前后空格方法
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" class="m3" name="content"/>
</li>
<li>
<input type="submit" value="提交"/>
</li>
</ul>
</form>
参考:
[url]http://blog.stevenlevithan.com/archives/faster-trim-javascript[/url]
[url]http://www.iteye.com/topic/1021677[/url]