日期:2014-05-16 浏览次数:20371 次
var str = 'aa bb cc dd ee fff'; str = str.replace(/\s+/g, ' ');
------解决方案--------------------
<!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)