从iframe触发到同级iframe

时间:2011-08-29 10:07:23

标签: javascript jquery iframe javascript-events iframe-app

Iframe.html的

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.js" type="text/javascript"></script>
    <script>
    $(function(){

    });
    </script>
</head>
<body>


<table border="1" width="100%" height="100%">
  <tr>
    <th><iframe id="i1" width="100%" height="100%"src="iframe_file1.html"></iframe></th>
    <th><iframe id="i2" width="100%" height="100%"src="iframe_file1.html"></iframe></th>
  </tr>

</table>

</body>
</html>

iframe_file1.html

<html>
 <head>
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.js"></script>
 <script>
 $(document).ready(function(){
        $('body').click(function(e){
            console.log("iframe clickq1");
            console.log(e);
            $('#i2', window.parent.document).contents().find('body').trigger(e);
        });
 });
 </script>
 </head>
    <body>
            <a href="#" onclick="alert('first link')">first link</a>
            <input type="button" value="Click me" id="button_click">
    </body>
</html>

点击链接或按钮事件时触发,但如果在此行中将i2更改为i1,则不会触发第二个iframe

$('#i2', window.parent.document).contents().find('body').trigger(e);
然后它工作为什么i2不工作我该怎么办?

0 个答案:

没有答案