gpt4 book ai didi

javascript - Jquery 删除空格

转载 作者:行者123 更新时间:2023-11-30 16:45:56 25 4
gpt4 key购买 nike

尝试从内容中删除不需要的空格和符号。

使用:

$('.infora .price .amount').text(function(index, text) {
return text.replace('£', '');
return text.replace(/ /g, '');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

<section class="infora">
<p class="price"><span class="amount">
13.95 </span>
</p>
</section>

井号已被移除,但空白仍然存在。

有什么想法吗?

最佳答案

使用\s+,这将删除所有空格字符。例如选项卡。使用 //g 只会删除空格字符。

return text.replace('£', '').replace(/\s+/g, ''); // Thanks to @JaromandaX

链接两个 replace 语句。因为你不能从一个函数返回两次。 return 之后的第二条语句不会执行。

编辑

您也可以将两个replace组合成一个regex

return text.replace(/[£\s]/g, '')

关于javascript - Jquery 删除空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31249259/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com