layer.prompt用法/字数限制

             layer.prompt({
                   formType: 2
                   ,value: data.count
                  // ,maxlength:100    
                   ,title: '修改数字'
                   ,id:'stock'
                   ,closeBtn: 1
                   ,btn:['确定','取消']
                   ,area: ['210px', '20px']
                   ,success:function (layero, index) {
                           // 在success的回调里增加限制
                           //当前情况仅限一个输入框
                           //replace 里可以填其他的正则匹配
                       $('#stock .layui-layer-input').attr({'rows':1,'maxlength':5,'onchange':"this.value=this.value.replace(/\\D/g,'')",'onkeydown':"this.value=this.value.replace(/\\D/g,'')",'onkeyup':"this.value=this.value.replace(/\\D/g,'')"});
                       $('#stock .layui-layer-input').css('resize',"none");
                       $('#stock .layui-layer-input').attr("placeholder","请输入数字,最大99999");
                   }
                   ,yes:function(index, layero){
                       // 获取文本框输入的值
                       var value = layero.find(".layui-layer-input").val();
                       if(value == data.stock){
                           layer.msg('数字没有变化',{time: 500, anim: 6});
                       }else if (value.length < 0) {
                           layer.msg('数字不能小于0',{time: 500, anim: 6});
                       } else {
                               //定义参数
                           var param = {
                               "id":id,
                               "count":value
                           };
                           JsPost("xxxxx", param, function (res) {
                               if (res.status) {
                                   obj.update({
                                       count: value    //更新修改的值而无需刷新表格
                                   });
                                   layer.msg(res.msg,{time: 1000, icon:6 });
                                   layer.close(index);
                               } else {
                                   layer.msg(res.msg,{time: 1500, anim: 6});
                               }
                           });

                       }

                   }
               });

 

posted @ 2024-04-13 14:54  大da脸  阅读(437)  评论(0编辑  收藏  举报