我有一個ID列表,其中沒有列表項。在我的jQuery腳本中,我有一個函數將#list中的HTML設置爲某些列表項。jQuery處理臨時元素
$('#list').click(function() {
$('#list').html("<li> blah </li> <li> blooh </li>");
});
但後來,當我試圖操縱$( '#名單禮'):
$('#list li').mouseenter(function() {
this.style.backgroundColor = "red";
});
它似乎並沒有工作。有任何想法嗎?
的可能重複[由動態生成的元素觸發的事件不會被事件處理程序捕獲](http://stackoverflow.com/questions/12829963/events-triggered-by-dynamical ly-generated-element-are-not-by-event-hand) –
and [Event binding on dynamic created elements?](http://stackoverflow.com/questions/203198/event-binding-on-dynamically-創建元素) –