自动消除文本框中的空格;js清除空格问题,去除空格问题 要完成此效果需要两个步骤
第一步:把如下代码加下代码加入到<head>区域中
function ignoreSpaces(string) {
var temp = "";
string = '' + string;
splitstring = string.split(" ");
for(i = 0; i < splitstring.length; i++)
temp += splitstring[i];
return temp;
}
第二步:把如下代码加入到<body>区域中
<center>
<pre>
</pre><font size="2">随意录入几个中间带空格的字符试试</font>.
</center>
<center>
<form>
<input type=text size=25 onBlur="this.value=ignoreSpaces(this.value);">
<input type=button value="Ok">
</form>
</center>
demo:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>自动消除文本框中的空格;js清除空格问题,去除空格问题 </title>
<SCRIPT LANGUAGE="JavaScript">
function ignoreSpaces(string) {
var temp = "";
string = '' + string;
splitstring = string.split(" ");
for(i = 0; i < splitstring.length; i++)
temp += splitstring[i];
return temp;
}
</script>
</head>
<body>
<center>
<pre>
</pre><font size="2">随意录入几个中间带空格的字符试试</font>.
</center>
<center>
<form>
<input type=text size=25 onBlur="this.value=ignoreSpaces(this.value);">
<input type=button value="Ok">
</form>
</center>
</body>
</html>