1<SCRIPT LANGUAGE="JavaScript">
 2<!--
 3//出处:网上搜集
 4// Trim() , Ltrim() , RTrim() 
 5String.prototype.Trim = function() 
 6
 7return this.replace(/(^\s*)|(\s*$)/g, ""); 
 8}
 
 9
10String.prototype.LTrim = function() 
11
12return this.replace(/(^\s*)/g, ""); 
13}
 
14
15String.prototype.RTrim = function() 
16
17return this.replace(/(\s*$)/g, ""); 
18}
 
19
20//-->
21
</SCRIPT>
22
23<input type="text" value="   前后都是空格    " id="space">
24<input type="button" value="去前后空格" onclick="javascript:document.getElementById('space').value=document.getElementById('space').value.Trim();document.getElementById('space').select();">
25<input type="button" value="去前空格" onclick="javascript:document.getElementById('space').value=document.getElementById('space').value.LTrim();document.getElementById('space').select();">
26<input type="button" value="去后空格" onclick="javascript:document.getElementById('space').value=document.getElementById('space').value.RTrim();document.getElementById('space').select();">
27<input type="button" value="还原" onclick="javascript:document.getElementById('space').value='     前后都是空格    ';">
28