我使用的引導
以下是我的代碼,以動態獲取飼料,然後通過編號爲師內追加添加它們在頁面上「飼料」:上動態添加按鈕註冊單擊事件的jQuery
$.ajax({
url: 'http://api.feedzilla.com/v1/categories/'+newsId+'/articles.json',
type: 'GET',
dataType: 'json',
// to execute when successfully got json response
success: function(response){
$.each(response.articles, function(){
var feed= "<div class='media well'>"+
"<div class='media-body'>"+
"<h4 class='media-heading'>"+this.title+"</h4>"+
"<h6>"+this.publish_date+"</h6>"+
"<p>"+this.summary+"</p>"+
"<a href='"+this.url+"' target='_blank'>Continue Reading</a>"+
"</div><br><br>"+
"<button class='showinfo btn pull-right' id='info'>Show Info</button>"+
"</div>";
$('#feeds').append(feed);
});
},
// to execute when error
error: function(jqXHR, textStatus, errorThrown){
alert("Server error!");
},
// execute at last whether success or error
complete: function(){
}
});
正如你所看到的,我添加了一個類'showinfo'以及id'info'來動態添加按鈕。
現在,以下是我的事件處理程序:
// SHOW INFO BUTTON CLICK HANDLER
$('.showinfo').click(function(){
alert('triggered');
});
但它不工作:(!!既不與ID:$( '#信息')點擊()! 如果我不」不要再增加了動態按鈕,它可以完美運行爲什麼會是這樣
的其他一千問題重複... –
id屬性應該是唯一的 – HarryFink