解决打开的小窗口回调参数的问题,layui

3 篇文章 0 订阅

问题:

         给用户新增优惠券,单个用户,单个优惠券,新增的话,用输入窗点击事件,点击后弹出一个子窗口列表页,选择数据后,点击确定,信息传回父窗口,主要是解决传值的问题。

解决思路:

使用的是layui的前端框架,如下代码:给输入框增加 selectUser()事件,

 

           <dl>
                <dt>选择用户</dt>
                <dd>
                    <asp:TextBox ID="txt_user" runat="server" CssClass="input normal" datatype="*" onclick="selectUser()"></asp:TextBox>
                    <input type="hidden" name="userId" value="" id="userId"/>
                </dd>
            </dl>

            <dl>
                <dt>选择优惠券</dt>
                <dd>
                    <asp:TextBox ID="txt_coupons" runat="server" CssClass="input normal" datatype="*" onclick="selectCoupons()"></asp:TextBox>
                    <input type="hidden" name="couponsId" value="" id="couponsId"/>
                </dd>
            </dl>

 

 

x

      <dl>

           <dt>选择用户</dt>

             <dd>

                 <asp:TextBox ID="txt_user" runat="server" CssClass="input normal" datatype="*" οnclick="selectUser()"></asp:TextBox>

                 <input type="hidden" name="userId" value="" id="userId"/>

               </dd>

           </dl>

 

            <dl>

               <dt>选择优惠券</dt>

             <dd>

                 <asp:TextBox ID="txt_coupons" runat="server" CssClass="input normal" datatype="*" οnclick="selectCoupons()"></asp:TextBox>

                 <input type="hidden" name="couponsId" value="" id="couponsId"/>

             </dd>

         </dl>

 

 

点击后触发下面代码,使用的是http://www.layui.com/doc/modules/layer.html,中的方法,

        // 选择用户
        function selectUser() {
            layer.open({
                type: 2,
                title: '选择用户',
                shadeClose: true,
                shade: 0.8,
                area: ['52%', '70%'],
                content: '../selectInfo/user_personal_list.aspx', //iframe的url
                btn: ['确定', '关闭'],
                yes: function (index) {
                    //当点击‘确定’按钮的时候,获取弹出层返回的值
                    var res = window["layui-layer-iframe" + index].callbackdata();
                    $('#txt_user').val(res.title);
                    $('#userId').val(res.id);
                    //打印返回的值,看是否有我们想返回的值。
                    console.log($('#userId').val());
                    //最后关闭弹出层
                    layer.close(index);
                },
                cancel: function () {
                    //右上角关闭回调
                }

            });
        }

 

 

x

 

        // 选择用户

     function selectUser() {

           layer.open({

               type: 2,

               title: '选择用户',

             shadeClose: true,

               shade: 0.8,

               area: ['52%', '70%'],

               content: '../selectInfo/user_personal_list.aspx', //iframe的url

             btn: ['确定', '关闭'],

               yes: function (index) {

                   //当点击‘确定’按钮的时候,获取弹出层返回的值

                 var res = window["layui-layer-iframe" + index].callbackdata();

                   $('#txt_user').val(res.title);

                 $('#userId').val(res.id);

                 //打印返回的值,看是否有我们想返回的值。

                 console.log($('#userId').val());

                   //最后关闭弹出层

                   layer.close(index);

              },

               cancel: function () {

                   //右上角关闭回调

            }

 

            });
        }

 

 

然后,我们在点击开的子窗口的页面,加上如下js代码,check事件,是选择事件,选中哪一行后,获取相应信息,然后把值传递给hidden的标签,然后把数据放入callbackdata回调函数,传给父窗口,OK,解决解决子窗口回调参数问题。

    <script type="text/javascript">
        var callbackdata = function () {
            var data = {
                id:  $('#couponsID').val(),
                title:$('#couponsName').val()
            };
            return data;
        }

        function check(obj) {
            var son = $(obj).parent();
            var id = son.next('input').val();
            var title = son.parent().next('td').find('a').html();
            $('#couponsID').val(id);
            $('#couponsName').val(title);
        }
    </script>

 

 

x

 <script type="text/javascript">

     var callbackdata = function () {

           var data = {

             id:  $('#couponsID').val(),

           title:$('#couponsName').val()

        };

       return data;

    }

 

        function check(obj) {

         var son = $(obj).parent();

           var id = son.next('input').val();

           var title = son.parent().next('td').find('a').html();

           $('#couponsID').val(id);

           $('#couponsName').val(title);

      }

   </script>

 

 

<wiz_tmp_tag id="wiz-table-range-border" contenteditable="false" style="display: none;">

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值