名称随id的变化而变化

        $("#user_id").change(function () {
            var uid = $(this).val();
            if (uid == '') {
                $("#user_name").text('');
            } else {
                $.get(getUserNameUrl+uid, function (result) {
                    if (result.code == 200) {
                        $("#user_name").html(result.data);
                    }
                }, 'json');
            }
        });

 2. 只允许输入数字,同时超过最大限制就变成最大

        $("[type=number]").keyup(function () {
            var max = $(this).attr('max');
            var val = $(this).val();
            if (max.length && val.length) {
                max = parseInt(max);
                val = parseFloat(val);
                if (val > max) {
                    val = max;
                }
                $(this).val(val);
            }
        });

<input name="duration_time" class="layui-input " type="number" id="duration_time" placeholder="单位:天,最长365天" max="365">

 

posted @ 2018-12-18 11:21  泥土里的绽放  阅读(228)  评论(0编辑  收藏  举报