要做第二個按鈕,我需要做些什麼?第一個按鈕運行平穩,但第二個不是,如果你點擊test_link它會顯示在第二個按鈕,其中創建由JavaScript提交按鈕以通過ajax發佈數據,由createhtml製作而不工作
<script src="http://localhost/googledrive/www/ci/2.1.3/social/assets/jquery/jquery-1.7.1.js"></script>
<script type="text/javascript" >
$(document).ready(function()
{
$(".comment_button").click(function(){
$.ajax({
type: "POST",
dataType : "json",
url: "http://localhost/googledrive/www/ci/2.1.3/social/index.php/talk/test",
data: { name: "John", time: "2pm" },
success : function(cont) {
if(cont){
$.each(cont, function(key, val) {
alert(key+" "+val);
});
}
}
});
return false;
});
$(".comment_link").click(function(e){
e.preventDefault();
var element = $(this);
var id = element.attr("post_id");
$("#"+id).html('<input><button class="comment_button">Second button, not work</button>');
return false;
});
});
</script>
<form method="post" action="http://localhost/googledrive/www/ci/2.1.3/social/index.php/talk/test/2">
<button class="comment_button">first button, this_button works</button>
</form>
<div id="7"></div>
<a href="http://localhost/googledrive/www/ci/2.1.3/social/index.php/talk/test/2" class="comment_link" post_id="7">test_link</a>
<br>
php code : <?php echo json_encode($_POST);?>
看看到了'。對()' http://api.jquery.com/on/它應該是你在找什麼。由於您的點擊在HTML實際製作之前已準備就緒,因此您使用的舊點擊甚至不知道該元素存在。 .on()類型的刷新元素來尋找他們 – ntgCleaner