<!DOCTYPE HTML> <html> <head> <meta charset="gb2312" /> <title></title> </head> <body> <script> var s = 'a b c d e f g'; var r = /\s+/g; s = s.replace(r, ' '); alert(s) </script> </body> </html> 楼主 试试。
var s = 'a b c d e f g'; while(s contians ' ') { s = s.replace(' ',' '); } alert(s)
<!DOCTYPE HTML>
<html>
<head>
<meta charset="gb2312" />
<title></title>
</head>
<body>
<script>
var s = 'a b c d e f g';
var r = /\s+/g;
s = s.replace(r, ' ');
alert(s)
</script>
</body>
</html>
楼主 试试。
while(s contians ' ') {
s = s.replace(' ',' ');
}
alert(s)