jQuery on.click不适用于动态加载的contet

时间:2017-06-15 12:35:15

标签: jquery ajax

我对jQuery不太熟悉。我想动态加载source.txt。在source.txt里面是一个按钮。这些按钮应该打开一个模态窗口。当我把source.txt代码放在main.php中时,它运行得很好,但是当我动态加载source.txt时,它就不起作用了。

我使用on.click作为委托,但它没有按预期工作。

main.php

<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Dialog - Animation</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<style>
iframe{
    overflow:hidden;
}
</style>
<script>
$(document).on("click","#link",function(){
 $("#include").load("http://www.damago.de/dev/source.txt"); 
});
$(document).on( "click","#opener", function() {
      $( "#dialog" ).dialog( "open" );
    });
  $( function() {
    $( "#dialog" ).dialog({
      autoOpen: false,
      width:700,
      height:700,
      show: {
      },
      hide: {
      }
    });
 } );
  </script>
</head>
<body>

<div id="include"></div>
        <a id="link" href="#">Include source.txt</a>
</body>
</html>


source.txt
<button id="opener">Open Dialog</button
<div id="dialog" title="Basic dialog">
 <iframe style="width:100%;height:100%;border:0px;"src="/test.com"></iframe>
</div>

0 个答案:

没有答案