zoukankan      html  css  js  c++  java
  • 如何在使用layer.prompt在输入值为空的情况下点击确定继续执行逻辑?

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

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

      示例:原代码如下:

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

       

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

    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("输入值为空!");
            }
        }
    }); 
    

     

     

  • 相关阅读:
    Data Structure and Algorithm
    Data Structure and Algorithm
    Data Structure and Algorithm
    Data Structure and Algorithm
    Data Structure and Algorithm
    Data Structure and Algorithm
    Data Structure and Algorithm
    Data Structure and Algorithm
    Data Structure and Algorithm
    Data Structure and Algorithm
  • 原文地址:https://www.cnblogs.com/Big-Boss/p/9455932.html
Copyright © 2011-2022 走看看