0

iframe ボタンのクリックに基づいて操作を実行しようとしていますが、実行できません。

HTML :-

<div class="content">
    Here my content displaying
    <script type="text/javascript">
    $(document).ready(function(){
      $('#ifrme_btn').click(function(){
        console.log('button clicked');
        $('#message_div', window.parent.document).hide();
      });

    });
    </script>
      <div id="message_div">
            After click on iframe button i want hide this div
    </div>

    <iframe id="Iframe">
    <html lang="en-US" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
    <title>Any Title</title>
    </head>
    <body id="ifrme-content">
        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor 
        incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud 
           <input type="button" id="ifrme_btn" name="Check Status" value="Clicked Iframe Button" />
    </body>
    </html>
    </iframe>
</div>

onclick on ifrme_btni want hidemessage_div

4

3 に答える 3

0

生成された要素を操作する場合は、.live("click") を使用します。

http://api.jquery.com/live/

例えば:

$("#ifrme_btn").live("click", function(){
    $("#message_div").hide();   
    }
});
于 2013-05-24T13:50:15.513 に答える
0

関数:

$(document).ready(function(){
      $('#ifrme_btn').click(function(){
        console.log('button clicked');
        $('#message_div', window.parent.document).hide();
      });

    });

メインドキュメントではなく、iframe 内にある必要があります。

于 2013-05-24T13:50:25.867 に答える
0

あなたはこのようにすることができます

HTML

  <iframe name="Iframe" id="Frame"></iframe>

jQuery

$('[name=Iframe]').contents().find('#ifrme_btn').click(function() {
  $('#message_div').hide();
});
于 2013-05-24T13:50:27.040 に答える