键入 jQuery 时用点替换逗号
Replace comma with a dot while typing jQuery
您好,我想在使用 jQuery 在文本输入字段中键入时用点替换逗号。我现在有这个代码;
$(document).on('change', '.unitprice', function() {
$(this).val().replace(/,/g, '.');
});
The class of the input field is unitprice
但它不起作用..而且我似乎无法在 google 上找到正确答案。有人知道如何实现这个吗?
您只是在更改变量而不是将其写回。
$(this).val($(this).val().replace(/,/g, '.'));
您好,我想在使用 jQuery 在文本输入字段中键入时用点替换逗号。我现在有这个代码;
$(document).on('change', '.unitprice', function() {
$(this).val().replace(/,/g, '.');
});
The class of the input field is unitprice
但它不起作用..而且我似乎无法在 google 上找到正确答案。有人知道如何实现这个吗?
您只是在更改变量而不是将其写回。
$(this).val($(this).val().replace(/,/g, '.'));