JS去除字符串中的所有空格

<!doctype html> <html> <head> <meta charset="utf-8"> <title>去除字符串中的所有空格</title> <script src="http://libs.baidu.com/jquery/1.11.3/j...
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>去除字符串中的所有空格</title>
<script src="http://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script>
</head>
<body>
<script>
function Trim(str) {
    var result;
    result = str.replace(/(^\s+)|(\s+$)/g, "");
    result = result.replace(/\s/g, "");
    return result;
}
var aa="我爱    我家,我爱          我的  祖国。您好,我叫  祖国。"
document.write(aa+"<br/>");
document.write("<br/>去除字符串中的所有空格: "+Trim(aa));
</script>
</body>
</html>

attachments-2020-06-I6y7wldB5ef6c3cec505a.jpg

你可能感兴趣的文章

相关问题

0 条评论

请先 登录 后评论
admin
admin

651 篇文章

作家榜 »

  1. admin 651 文章
  2. 粪斗 185 文章
  3. 王凯 92 文章
  4. 廖雪 78 文章
  5. 牟雪峰 12 文章
  6. 李沁雪 9 文章
  7. 全易 2 文章
  8. Stevengring 0 文章