2010-12-10 111 views
2

如果頁面還包含mootools-core.js,則以下jQuery代碼段將失敗。mootools與jQuery不兼容

foo2對象沒有元素。這是因爲find(「#content」)無法返回任何內容。

var foo1 = $("<div><div id='content'>HAGGIS</div></div>"); 
var foo2 = foo1.find("#content"); 

alert("foo1("+foo1.length+"): "+$('<div>').append(foo1.clone()).remove().html() 
    + "\n\n" + 
     "foo2("+foo2.length+"): "+$('<div>').append(foo2.clone()).remove().html()); 
+1

您正在經歷什麼讓您認爲它不是?我只是把它放在這裏:http://jsfiddle.net/eSGBx/它看起來好像在展示你所期望的。 – spinon 2010-12-10 01:34:36

回答

0

使getElementById副本,讓jQuery的調用一個來代替。在此之前得到的mootools進口:

Element.prototype._getElementById = Element.prototype.getElementById; 

然後做一個搜索,並在您的jQuery源更換爲context.getElementByIdcontext._getElementById取代。 jquery-1.4.4中只有4次出現。

1

的getElementById是Document對象,所以這是正確的代碼:

Document.prototype._getElementById = Document.prototype.getElementById; 

在Chrome這僅適用於(9.0.597.98),我會嘗試其他的解決方案...

新編輯:Happly得到它了!適用於所有測試過的瀏覽器(hoooray!):

document._getElementById = document.getElementById;