gpt4 book ai didi

javascript - 使用 jQuery 替换数字以外的文本

转载 作者:行者123 更新时间:2023-11-30 06:32:36 24 4
gpt4 key购买 nike

我正在尝试使用 jQuery 替换一些文本,留下数字。

在 jQuery 中替换文本很容易,但我对正则表达式知之甚少,无法单独保留数字部分。

这是 HTML:

<div class="example">10 Examples</div>

我想做的是将 10 Examples 更改为其他内容,但保留数字部分。

最佳答案

parseInt 用于非正则表达式解决方案。

$(".example").text(function(i, txt) {

return parseInt(txt, 10) + " your new message";
});

关于javascript - 使用 jQuery 替换数字以外的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16639459/

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