1
<SCRIPT LANGUAGE="JavaScript">
2
<!--
3
//出处:网上搜集
4
// Trim() , Ltrim() , RTrim()
5
String.prototype.Trim = function()
6
{
7
return this.replace(/(^\s*)|(\s*$)/g, "");
8
}
9
10
String.prototype.LTrim = function()
11
{
12
return this.replace(/(^\s*)/g, "");
13
}
14
15
String.prototype.RTrim = function()
16
{
17
return 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
<SCRIPT LANGUAGE="JavaScript">2
<!--3
//出处:网上搜集4
// Trim() , Ltrim() , RTrim() 5
String.prototype.Trim = function() 6
{ 7
return this.replace(/(^\s*)|(\s*$)/g, ""); 8
} 9

10
String.prototype.LTrim = function() 11
{ 12
return this.replace(/(^\s*)/g, ""); 13
} 14

15
String.prototype.RTrim = function() 16
{ 17
return 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




浙公网安备 33010602011771号