2012-07-10 226 views
1

jQuery中是否存在啓動dom元素創建的事件?我嘗試了加載,但這不適用於例如跨度。jQuery - 創建元素時觸發事件

+2

分享代碼?你嘗試過什麼? – 2012-07-10 09:13:35

+0

否(...........) – Matt 2012-07-10 09:14:11

+1

請把你的代碼通過 – 2012-07-10 09:14:20

回答

1

你可以嘗試DOMNodeInserted事件:當不是Attr節點以外的其他節點已作爲另一個節點的子

用戶代理必須分派此事件類型。 Attr節點已添加到Element節點時,用戶代理可能會分派此事件。插入後必須發送此事件。此事件的事件目標必須是要插入的節點。

$(document).bind('DOMNodeInserted', function(){ 
    ... 
}) 
+0

這在FF/Chrome中可用,可悲的是在IE中不起作用。嘆。 – MollyRazor 2012-07-10 09:25:35

0

您可以創建元素的功能伸到封閉,並觸發作爲一個新的元素創建如

var newElement=function(newElement){ 
        var k=$(newElement);//Create a new element 
/*You can add extra operations to the element*/ 
        triggerFunction(someVariable); //Function triggered after the creation of new element 
        }; 

var triggerFunction=function(someVariable){//Some function}; 

希望其他功能下面的代碼說明了情況well.Here我們一個觀察者,無論何時創建一個新元素都會被觸發。

相關問題