在 jquery 中用逗号输入后替换点字符

Replace dot character once entered by a comma in jquery

我需要用逗号替换用户输入的点字符。 我写了这段代码,但它没有给出跳跃的结果

$(".dot").keyup(function (event) {

     val = $(this).val();
     length = val.length;
     if (event.key == '.') {
         event.stopPropagation();
         $(this).val(val.substring(0, length)+",");
     }
 });

您尝试过使用字符串方法替换吗?

var res = str.replace(".", ",");
Please try this.

$('input[type = "text"]').on("keyup", function (e) {
  var val = $(this).val();
    var str=val.replace('.',',');
    $(this).val(str);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type='text' id='txtVal' />