【问题标题】:jQuery remove character from textjQuery从文本中删除字符
【发布时间】:2014-05-21 20:53:56
【问题描述】:

我有以下代码:

$('#table1 .set2').each(function()
{
    alert($(this).html());
});

这会带回当前在警报框中的 % 范围。

99%
87%
12%

我需要做的是删除% 字符,这样我就可以使用一个数字。

欢迎提出任何建议。

【问题讨论】:

  • 你能不能不做一个简单的x.replace('%', '')

标签: jquery html string character


【解决方案1】:

变化:

$(this).html()

到:

$(this).html().replace('%','')

jsFiddle example

【讨论】:

  • 另一个问题 - 我如何将此 html 转换为数字,以便将它们加在一起?
【解决方案2】:

我相信,这应该对你有用

$('#table1 .set2').each(function()
    {
        var number=$(this).html().trim().slice(0,-1);
        alert(number);
    });

【讨论】:

    猜你喜欢
    • 2022-01-16
    • 2011-02-26
    • 2015-03-24
    • 2014-12-19
    • 2013-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多