Remove Commas with Jquery

前端 未结 6 2070
北荒
北荒 2021-02-12 22:02

I am in need of some code that removes commas from a string. I currently have a variety of numbers in the number_format() for PHP. I use Jquery to post certain things to a updat

相关标签:
6条回答
  • 2021-02-12 22:37

    replace

    var noCommas = $('.money').text().replace(/,/g, ''),
        asANumber = +noCommas;
    
    0 讨论(0)
  • 2021-02-12 22:47

    Less is more! (sometimes!)

    $(document).ready(function(){
    var **stripString** = $('.money').text().replace(/,/g, '');
    $('.*money*').text(**stripString**);
    });
    
    0 讨论(0)
  • 2021-02-12 22:55

    Could you please try with this , will remove comma on click on textbox , after focusout thousand seperated will be added...

    $( "#salary" ).click(function() {
    
       $( "#salary" ).val(  $("#salary").val().replace(/,/g, ''));
    
    });
    
    
    
    $( "#salary" ).blur(function() {
    
       $( "#salary" ).val( addCommas($( "#salary" ).val());
    
    });
    
    function addCommas(nStr) {
    
        nStr += '';
        var x = nStr.split('.');
        var x1 = x[0];
        var x2 = x.length > 1 ? '.' + x[1] : '';
        var rgx = /(\d+)(\d{3})/;
        while (rgx.test(x1)) {
            x1 = x1.replace(rgx, '$1' + ',' + '$2');
        }
        return x1 + x2;
    
    }

    0 讨论(0)
  • 2021-02-12 23:00

    you can do like this

    var str=$(".money").text();
    var str2=   str.replace(",", "")
    
    0 讨论(0)
  • 2021-02-12 23:01

    This is a clean way to get rid of the commas in one line, without loops.

        var cleanNumber = $("#selector").val().split(",").join("");
    

    Hope can help u!

    0 讨论(0)
  • 2021-02-12 23:01

    use replace function of javascript for removing , in a string

    var result = jQuery('.money').html().replace(',', '');
    alert(result);
    
    0 讨论(0)
提交回复
热议问题