layui彈出層父頁面與子頁面的傳值,父頁面調子頁面的方法。


$('.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("先選擇行")
}
})


<script>
//子窗口
function child(d) {
alert(d)
//在這里你可以寫你的jquery $(function(){ }) // 等等操作

}
</script>




//父子頁面相互調用方法
//父頁面
<body>
<a data-url="bbbb.html" id="parentIframe">小小提示層</a>
<input id="shuzhi" />
<button class="but_par">父頁面</button>
</body>
<script src="../jquery-1.9.1.min.js"></script>
<script src="layer/layer.js"></script>
<script>
$(function(){
$("#parentIframe").click(function(){
var a = $(this).attr("data-url");
layer.open({
type: 2,
content: a,
success: function(layero, index){
var body = layer.getChildFrame('body', index);//獲取子頁面內容
var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe頁的窗口對象,執行iframe頁的方法:iframeWin.method();
body.find("#transmit").click();//執行子頁面的方法
body.find('input').val('Hi,我是從父頁來的')
$(".but_par").click(function(){
alert(222);
})
}
});
})
})
</script>




//子頁面
<body>
<input id="name" value="不滿意" />
<button id="transmit">給父層傳值</button>
</div>
</body>
<script>
$(function(){
$(document).on("click","#transmit").click(function(){
parent.$("#shuzhi").val($("#name").val());
parent.location.reload(); 刷新父頁面
//關閉layer彈出層
var index = parent.layer.getFrameIndex(window.name); //獲取窗口索引
parent.layer.close(index);
})
window.parent.$(".but_par").click();//執行父頁面的事件
})
</script>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM