<input type="text" name="mytxt" value=" 12345678 " />
<input type="button" name="cmd1" onclick="mytxt2.value=mytxt.value.trim()" value="去两边的空格"/>
<input type="text" name="mytxt2"/>
<input type="button" name="cmd1" onclick="mytxt3.value=mytxt.value.ltrim()" value="去左边的空格"/>
<input type="text" name="mytxt3"/>
<input type="button" name="cmd1" onclick="mytxt4.value=mytxt.value.rtrim()" value="去右边的空格"/>
<input type="text" name="mytxt4"/>
<script language="
javascript">
String.prototype.trim=function(){
return this.replace(/(^s*)|(s*$)/g, "");
} // www.jb200.com
String.prototype.ltrim=function(){
return this.replace(/(^s*)/g,"");
}
String.prototype.rtrim=function(){
return this.replace(/(s*$)/g,"");
}
</script>