如何在使用layer.prompt在输入值为空的情况下点击确定继续执行逻辑?

2019-04-25 15:48:16

 突然发现在使用LayUI时,用到弹出层layer.prompt时,如果文本框输入值是空的话点击确定没有反应,不能向下执行。

但是我又需要在这种情况下去继续执行判断或逻辑时该怎么做??

  示例:原代码如下:

1
2
3
4
5
6
7
8
9
layer.prompt({
    formType: 2,
    title: '请填写排除原因(注:必填项)',
    area: ['500px''150px'],
    btnAlign: 'c'
}, function(value, index, elem){
    alert(value);
    layer.close(index);
});

   

  去官网查看文档可以知道layer.prompt也是继承layer.open的,所以可以改成如下代码就可以实现刚才描述的需求了,如下所示:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
layer.prompt({
    formType: 2,
    title: '请填写排除原因(注:必填项)',
    area: ['500px''150px'],
    btnAlign: 'c',
    yes: function(index, layero){
        // 获取文本框输入的值
        var value = layero.find(".layui-layer-input").val();
        if (value) {
            alert("输入值为:" + value);
            layer.close(index);
        else {
            alert("输入值为空!");
        }
    }
});

 

 


  • 2017-12-25 11:07:58

    mogodb 备份

    error connecting to db server: server returned error on SASL authentication

  • 2017-12-25 15:53:15

    MongoDB3.4版本配置详解

    配置文件方面,mongod和mongos有很多相同之处,下文中如有区别之处将会特别指出。 在一个节点上,通常同时启动mongod和mongos进程是正常的,他们之间不存在资源竞争,但是为了避免冲突,我们希望它们使用各自的配置文件,比如mongod.conf、mongos.conf;mongodb的某些平台下的安装包中没有自带配置文件,需要开发者自己创建。