给你一个去空格方法: <script language="vbs"> function js_trim(s) js_trim=trim(s) end function </script> 调用如下: function re() { if(js_trim(document.Form1.txtMiMaQR.value)=="") { alert('1111111!'); return false; } return true;} 给分;给分;给分;给分;给分;给分;给分;给分;给分;给分;
<script language="JavaScript"> String.prototype.trim = function () { return this.replace(/^\s*|\s*$/g,''); }; alert("Begin"+" he he ".trim()+"End."); </script>以后字符串就可以直接使用.trim()了
<script language=Javascript> //自己动手为string添加Trim
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, "");}
var str = " meizz ";
alert(str.Trim());
alert(str.Ltrim());
alert(str.Rtrim());
</script>
str.replace(" ","");
<script language="vbs">
function js_trim(s)
js_trim=trim(s)
end function
</script>
调用如下:
function re()
{
if(js_trim(document.Form1.txtMiMaQR.value)=="")
{
alert('1111111!');
return false;
}
return true;}
给分;给分;给分;给分;给分;给分;给分;给分;给分;给分;
String.prototype.trim = function () {
return this.replace(/^\s*|\s*$/g,'');
};
alert("Begin"+" he he ".trim()+"End.");
</script>以后字符串就可以直接使用.trim()了