时光绘梦集
0
位置: 代码 正文

夏夜万年 2025/02/02 周7

便捷弹出层

自己编的一个便捷使用layer的弹出层函数,共两个参数。

第一个可以是字符串,可以是数组,字符串就显示提示,数组就生成输入框。

第二个是回调函数,根据接受到的内容进行处理。比如确定取消的处理,或者输入框的处理。

const tanchu = (data, call) => {
    let con = '';
    if (typeof data === 'string') {
        con = data
    } else if (Array.isArray(data)) {
        con = data.map((item, index) => `${item}<textarea id="it${index}" required></textarea><br>`).join('')
    }
    layer.open({
        type: 1,
        title: false,
        content: `<div style="padding:20px;">${con}</div>`,
        area: ['auto', 'auto'],
        closeBtn: 0,
        btn: ['确定', '取消'],
        yes: function(index, layero) {
            if (Array.isArray(data) && call) {
                const inputs = data.map((_, index) => layero.find(`#it${index}`).val());
                call(inputs)
            } else if (call) {
                call(true)
            }
            layer.close(index)
        },
        btn2: function(index) {
            layer.close(index);
            return false
        }
    })
};

使用方法

#提示信息
tanchu("提示内容");
#对话框
tanchu("提示内容",回调函数);
#输入框
tanchu(数组,回调函数);


上一篇:人生真正的需求
下一篇:php堆排序
    【运行状态】
获取数据中...