jQuery removing '-' character from string

后端 未结 3 832
南方客
南方客 2020-12-08 01:46

I have a string \"-123445\". Is it possible to remove the \'-\' character from the string?

I have tried the following but to no avail:

$mylabel.text(         


        
3条回答
  •  感情败类
    2020-12-08 02:14

    $mylabel.text("-123456");
    var string = $mylabel.text().replace('-', '');
    

    if you have done it that way variable string now holds "123456"

    you can also (i guess the better way) do this...

    $mylabel.text("-123456");
    $mylabel.text(function(i,v){
       return v.replace('-','');
    });
    

提交回复
热议问题