JS trim函数

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
<meta charset="utf-8" />
    <script>
        function trim(name) {
            return name.replace(/^\s+/, '').replace(/\s+$/, '');
        }

        var msg = '        我是字符串           ';
        //msg = msg.replace(/^\s+/, '').replace(/\s+$/,'');
        //alert('========'+msg+'============');
        alert('========' + trim(msg) + '========');
    </script>
</head>


<body>


</body>
</html>
posted @ 2018-03-20 22:14  dxm809  阅读(110)  评论(0编辑  收藏  举报