<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
1
<
SCRIPT
LANGUAGE
="JavaScript"
>
2 String.prototype.trim = function ()
3 {
4 return this .replace( / ( ^ \s * ) | (\s * $) / g, "" );
5 }
6 function test(te)
7 {
8 alert (te.trim());
9 alert(te.length);
10 alert(te.trim().length);
11
12 }
13 </ SCRIPT >
14 < html >
15 < body >
16 < form name ="form1" method ="post" >
17 < p >
18 < input type ="text" id ="te" name ="textfield" >
19 </ p >
20 < p >
21 < input type ="button" name ="Submit" value ="提交" onClick ="test(document.getElementById('te').value)" >
22 </ p >
23 </ form >
24 </ body >
25 </ html >
26
2 String.prototype.trim = function ()
3 {
4 return this .replace( / ( ^ \s * ) | (\s * $) / g, "" );
5 }
6 function test(te)
7 {
8 alert (te.trim());
9 alert(te.length);
10 alert(te.trim().length);
11
12 }
13 </ SCRIPT >
14 < html >
15 < body >
16 < form name ="form1" method ="post" >
17 < p >
18 < input type ="text" id ="te" name ="textfield" >
19 </ p >
20 < p >
21 < input type ="button" name ="Submit" value ="提交" onClick ="test(document.getElementById('te').value)" >
22 </ p >
23 </ form >
24 </ body >
25 </ html >
26