2011-10-25 77 views
1

易於媒介和啓動的用戶。鑑於以下文件:事件完成後加載jquery腳本

HTML:

<html> 
    <head> 
    <script> 
     $(document).ready(function() 
     { 
      $("#fashion").onclick(function() 
      { 
      $get("ajax.php", { section: fashion}, function(result) 
      { 
       $("#container").html(result); 
      }); 
      }); 

      $("div").click(function() 
      { 
      var identification = $(this).attr("id"); 
      alert(identification); 
      }); 
     }); 
    </script> 
    </head> 
    <body> 
    <div id="fashion"> 
     Click me 
    </div> 

    <div id="container"> 
    <div> 

    <div id="test"> 
     Test 
    </div> 
    </body> 
</html> 

我從另一頁 「ajax.php」 的方法

<?php 
if($_GET['fashion']) 
{ 
    ?><div id="fashion_content">This is a random text</div><?php 
} 
?> 

事情以前稱爲HTML信息是與函數$ (「div」)。單擊(函數...在腳本部分不會返回由ajax get方法生成的div的id(div id =「fashion_content」),但只有其他(「fashion」,「container 「,」test「)。 另一方面,當我把div後面的jquery函數在ajax.php文件如下原理:

<?php 
if($_GET['fashion']) 
{ 
    ?><div id="random">This is a random text</div> 

    <script> 
      $("div").click(function() 
      { 
      var identification = $(this).attr("id"); 
      alert(identification); 
      }); 
    </script> 
    <?php 
} 
?> 

我想我完成了get事件後重新加載腳本(或唯一的功能)。但是如何?

回答

2

嘗試

$("div").live('click',function() 
    { 
    var identification = $(this).attr("id"); 
    alert(identification); 
}); 

也可以去$(document).ready()之外,以加快執行

在這個片段中,你的php不會需要返回腳本添加click事件。

+0

那是個快速的哥們!謝謝! –