js 删除字条串首尾空格

    <script type="text/javascript" language="javascript">
        function caculate()
        {
            var flag ="       中国       ";
            alert(flag+"原长度为:"+flag.length);

            alert(flag+"删除首尾空格后,长度为:"+flag.trim().length);
        }
   
    String.prototype.trim = function()
    {
        return this.replace(/(^\s*)|(\s*$)/g, "");
    }
    </script>

posted @ 2008-12-30 16:16    阅读(428)  评论(1编辑  收藏  举报