javascript - 从 Jquery 中的字符串中删除所有逗号

标签 javascript jquery html css

我有很多类,如果其中存在任何逗号,我想删除其中的逗号。

我写了下面的代码,但代码不能正常工作。第二类值替换为第一类值。

   
var removebox = $(".remove"),
removeboxHtml = removebox.html();
removebox.html(removeboxHtml.replace(/,/g , ''));
<html>
  <head>
    <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.12.4.min.js"></script>
  </head>
  <body>
    <span class="remove">,17500000</span>
    <span class="remove">,2479000</span>
  </body>
</html>

最佳答案

试试这个。更新了您的代码:

   

$(".remove").each(function(){
   
    $(this).html($(this).html().replace(/,/g , ''));
});
   
<html>
<head>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.12.4.min.js"></script>
</head>
<body>
<span class="remove">,17500000</span>
<span class="remove">,2479000</span>
</body>
</html>

关于javascript - 从 Jquery 中的字符串中删除所有逗号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39685882/

相关文章:

javascript - 在 JavaScript 中抽象掉异步/ promise ?

javascript - Jquery根据类搜索并显示图像

jquery - 使用选择选项重置滑动按钮

jquery - 为什么我不能让我的 jQuery 左滚动动画工作?

html - 水平居中 2 列 div,无需修改 HTML(仅 CSS)

javascript - 状态更改后从子组件重新渲染

javascript - 进入页面时如何转到特定 anchor (不起作用)

jquery - CSS div 增加高度但不要降低它

html - 我正在尝试删除空间,并且在侧面滑动和缓出的图像不会在纯 CSS 中缩放

html - *ngIf...当数据为空时,为mat-checkbox设置disabled=true