2010-12-10 58 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;