:D
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>去空格</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
//去两边空格
String.prototype.trim = function(){
return this.replace(/(^\s*)|(\s*$)/g, "");
};
//去所有空格
String.prototype.trimAll = function(){
return this.replace(/(^\s*)|(\s*)|(\s*$)/g, "");
};
function PeripheralTrim(){
var tmp = document.getElementById("inputid").value.trim();
document.getElementById("inputid1").value = tmp;
}
function AllTrim(){
var tmp = document.getElementById("inputid").value.trimAll();
document.getElementById("inputid1").value = tmp;
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<input type="button" onclick="PeripheralTrim()" value="去两边空格"/><br>
<input type="button" onclick="AllTrim()" value="去所有空格"/><br>
<input type="text" id="inputid"/><br>
<input type="text" id="inputid1"/>
</BODY>
</HTML>