1. 程式人生 > >jquery_iframe父子級頁面事件使用~

jquery_iframe父子級頁面事件使用~

posit alert pos tom log 使用 color left mar

1、index.html

<body topmargin=0 leftmargin=0‘ style="background:#ccc">    //這裏的屬性只是為了全屏下邊無間隙
  index.html <iframe src="main.html" id="indexMain" style="margin-bottom:-5px;position:relative;"></iframe>    //這裏的樣式的為了跳轉之後移動端input輸入完成之後下邊無間隙 </body> <script> /*父級頁面事件*/ function oIndexFn(){ alert("父級頁面index.html事件調用成功");
} /*調用子頁面事件*/ $(document).click(function(){
  alert("您點擊的是父頁面[index]") $(
"#indexMain")[0].contentWindow.oMainFn(); //iframe的id }) </script>

2、main.html

<body style="background:#f0f0f0">
    main.html
</body>

<script>
/*父級頁面事件*/
    function oMainFn(){
            alert(
"子頁面main.html事件調用成功"); } /*調用子頁面事件*/ $(document).click(function(){
  alert("您點擊的是子頁面![main]") parent.window.oIndexFn();
//調用父級頁面事件 }) </script>

技術分享圖片

jquery_iframe父子級頁面事件使用~