Remove Commas with Jquery

前端 未结 6 2075
北荒
北荒 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: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;
    
    }

提交回复
热议问题