最多输入两位小数,适配移动端

$("input").bind('input propertychange', function() {
    var value = $(this).val();
    if(value.length > 0) {
        var temp = value.split(".");
        if(temp.length >= 2) {
            var l1 = temp[0].length + 1;
            var l2 = 0;
            if(temp[1].length > 2) {
                l2 = 2;
            } else {
                l2 = temp[1].length;
            }
            value = value.substr(0, l1 + l2);
        }
    }
    $(this).val(value);
});

 

posted @ 2016-11-07 17:17  前进中的蜗牛  阅读(262)  评论(0编辑  收藏  举报