js清除左右空格

<html>
<head>
</head>
<body>
<script>
var aa='   sdfsdf   ';
function trim(str){
return str.replace(/(^\s*)|(\s*$)/g,''); 
}
alert(trim(aa).length);
</script>
</body>
</html>
隐藏