使用LAYUI父页面向子页面传参

预想效果:


选择某行后,单击编辑按钮,获取到选择的行的数据


实现:

表格使用datatables,自定义编辑按钮:

buttons: [
                'copyHtml5',
                'excelHtml5',
                'csvHtml5',
                'pdfHtml5',
                'print',
                {
                    text: '编辑',
                    className: 'editRow',
                },
            ]
按钮事件:

$('.mytable').on('click', '.editRow', function () {
        var table = $('#table_id_example').DataTable();
        var rowData = table.rows({selected: true}).data()[0];
        if (rowData) {
            layer.open({
                title: this.text,
                type: 2,
                skin: 'layui-layer-rim', //加上边框
                area: [window.screen.width / 2 + 'px', window.screen.height / 2 + 'px'], //宽高
                maxmin: true, //开启最大化最小化按钮
                content: "taskDetail.html",
                success: function (layero, index) {
                    // 获取子页面的iframe
                    var iframe = window['layui-layer-iframe' + index];
                    // 向子页面的全局函数child传参
                    iframe.child(rowData);
                }
            })
        } else {
            alert("先选择行")
        }
    })

.mytable是一个div,包裹了我们的表格

taskDetail.html是我们的子页面,其中有一个全局函数child:

<script>
    function child(d) {
      alert(d)
    }
</script>


这样子,在子页面上就可以取到父页面传过来的参数,效果图:


细节之处暂时忽略,有空再补。


参考资料:http://fly.layui.com/jie/2148/

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值