layer父向子传值

最近使用layer的弹窗功能,在传参上遇到了问题。 
有两种情况。 
1. 父页面给子页面传参;这个可以在url后拼接,比如test.html?a=1 
2. 父页面获取子页面操作DOM

说明:本文实现了第二种,我看到第一种方案的实现方法是在父页面中用正则表达式去搜索test.html?a=1 这样来达到获取参数

参考信息http://blog.csdn.net/ReturningProdigal/article/details/53541337

        layer.open({
            title: '请填写信息',
            type: 2, //设置为2则可以跳转页面
            area: [width, height],
            shadeClose: true, //点击遮罩关闭
            content: 'form.jsp',
            success: function(layero, index){
                     //注意这里的#sid是iframe页面中的一个标签id
                    var jquerySendHelloButton = $("#sid", layero.find("iframe")[0].contentWindow.document);  
                    jquerySendHelloButton.attr("value", sid );  

              },
        });

在iframe页面用一个标签,为了不影响页面,设置为隐藏

    <!-- 用来存储父页面传过来的id -->
    <input type="text"   id="sid" style="display:none"> 

注意,这里的sid和这里sid对应

var jquerySendHelloButton = $("#sid", layero.find("iframe")[0].contentWindow.document);  

猜你喜欢

转载自blog.csdn.net/ghostxbh/article/details/81539751