<html> <head> <script> var a = "123\nsdf\n3\n4"; a=a.replace(/\n/g,',') alert(a) </script> </head> <body> <h2>方式是 : / + [替换前字符] + /g 即可,注意,不要带引号</h2> </body> </html>