我有很多类,如果其中存在任何逗号,我想删除其中的逗号。
我写了下面的代码,但代码不能正常工作。第二类值替换为第一类值。
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/