1. 程式人生 > 實用技巧 >layui的子傳父值

layui的子傳父值

1.html(父頁面)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./layui/css/layui.css" media="all">
</head
> <body> <script src="./layui/layui.js "></script> <script> layui.use( ['layer'], function(){ var layer = layui.layer //彈層 // iframe層 layer.open({ type: 2, // title: 'layer mobile頁', shadeClose:
true, // shade: 0.8, // area: ['380px', '90%'], content: '2.html' //iframe的url }); window.gotoHref=function(type){ if(type == '1'){ console.log(1) }else if(type == '2'){ console.log(
2) }else if(type == '3'){ console.log(3) } } // var _tools = { // func1: function(){ // console.log('func1'); // } // } // window.tools = _tools; }); </script> </body> </html>

2.html(子頁面)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <a data-type="1" href="javascript:;">1</a>
    <a data-type="2" href="javascript:;">2</a>
    <a data-type="3" href="javascript:;">3</a>
    <script src="./layui/layui.js"></script>
    <script src="./layui/lay/modules/jquery.js"></script>
    <script src="layui/jquery1.9.0.min.js"></script>
    <script>
        $('a').click(function(){
            var type=$(this).attr('data-type');
            parent.gotoHref(type)
        })

        // parent.tools.func1();
    </script>
</body>
</html>