我有下面的代碼在我的網頁:爲什麼這個點擊處理程序不能在JQuery中工作?
var offer_link = $('<a>').addClass('fc-offer-link');
offer_link.click(function() {
alert('Hello');
});
offer_link.attr('href', "#" + this.id);
offer_link.append(this.subject);
this.list_item = $('<li>');
this.list_item.append(offer_link);
但即使鏈接出現在頁面上,處理程序不會被調用。這是怎麼回事?
[SSCCE(http://sscce.org)請。 –
在安裝點擊處理程序之前,您是否正在等待文檔使用'$(document).ready()'加載?或者在文檔的末尾(不在HEAD部分中)運行文檔的主體? – jfriend00
'this'是指什麼?另外,我想冒險改變爲'$(offer_link).live('click',function(){alert(...);});'可能會工作。 –