微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用自动分隔符正确输入光标不跳跃

如何解决使用自动分隔符正确输入光标不跳跃

编辑输入时如何使光标不跳?在我想要编辑输入光标跳入结束输入的当前时间 HTML

<input type="text" class="form-control numbercurrency" onblur="pensionRateByCpiIndex()" name="meals_living_expression" id="meals_living_expression" required onwheel="this.blur()" />
<input type="text" class="form-control numbercurrency" onblur="pensionRateByCpiIndex()" name="other_expenses" id="other_expenses" required onwheel="this.blur()" />
<input type="text" class="form-control number-disable total font-weight" name="total_cost" id="total_cost" onwheel="this.blur()" disabled required />

和 Jquery

$('input.numbercurrency').keyup(function (event) {
    // skip for arrow keys
    if (event.which >= 37 && event.which <= 40) return;

    // format number

    $(this).val(function (index,value) {
        return value
            .replace(/\D/g,"")
            .replace(/\B(?=(\d{3})+(?!\d))/g,".");
      
    });
});

计数函数

   $(function () {
        $("#meals_living_expression,#other_expenses").keyup(function () {
            $("#total_cost").val(convertToNumber($("#meals_living_expression").val()) + convertToNumber($("#other_expenses").val()));
    
            // format number
    
            $("#total_cost").val(function (index,value) {
                return value
                    .replace(/\D/g,"")
                    .replace(/\B(?=(\d{3})+(?!\d))/g,".");
            });
        });
    });

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。