<br> <br>사용방법<script type="text/javascript"> <BR>function trim(str){ //删除左右两端的空格 <BR>return str.replace(/(^\s*)|(\s*$)/g, ""); <BR>} <BR>function ltrim(str){ //删除左边的空格 <BR>return str.replace(/(^\s*)/g,""); <BR>} <BR>function rtrim(str){ //删除右边的空格 <BR>return str.replace(/(\s*$)/g,""); <BR>} <BR></script><script> <BR>function aaa() <BR>{ <BR>var s=document.getElementById("文本框ID").value; <BR>alert(trim(s)); <BR>} <BR></script>