单击按钮时更新div,单击另一个按钮生成按钮时

单击按钮magic1magic2 ,div mybox将更新为文本,按钮ID和按钮( magic1magic2不同)。

单击新生成的按钮后,它应显示box div中新生成按钮的按钮ID。 当我单击新生成的按钮时, box div不会更新。 这是代码。

jquerycode.php是初始文件。 单击magic1magic2按钮,Ajax将调用session.php页面。

jquerycode.php文件

      My jQuery Ajax test  #mybox { width: 300px; height: 250px; border: 1px solid #999; } #box { width: 300px; height: 250px; border: 1px solid #999; position: absolute; right:210px; }    $(document).ready(function(){ $(".magic_button").click(function() { var data = $(this).attr('id'); //alert (data); $.ajax({ type: "POST", url: "session.php", data: { 'id': data } }).done(function(msg) { $("#mybox").html(msg); }); }); });   $(".fir").click(function() { var dataa = $(this).attr('id'); alert ("hello"); $.ajax({ type: "POST", url: "jquerycode.php", data: { 'q': dataa } }).done(function(msg) { $("#box").html(msg); return false; }); });    The following div will be updated after the call:
<!-- -->

session.php文件

       

如果您可以将JQuery Live()用于动态生成元素,那么最好:

 $("a.offsite").live("click", function(){ alert("Goodbye!"); }); // jQuery 1.3+ 

不推荐使用Beca JQuery Live()你需要在()上使用JQuery

 $("#elementid").on("click", function(event){ alert($(this).text()); });