<script> window.onload=function(){ var a = "杭州 上海 合肥" var b = a.replace(/\s+/g,","); alert(b) } </script>
结果:杭州,上海,合肥