可能重复:
我在这里遇到了一些麻烦,如果还没有加载jQuery以运行我的脚本,我将加载它。我的脚本被插入到别人网站的主体标签中。我的问题是jquery仅仅通过加载它(Jquery)就与mootools冲突(Jquery)。
这是我的剧本:
var attemptCount=0;
if(typeof jQuery=='undefined') {
var script=document.createElement('script');
script.type='text/javascript';
script.src='https://ajax.googleapis.com/ajax/.../1.6.2/jquery.min.js';
document.getElementsByTagName('head')[0].appendChild(script);
}
function init(){
if(arguments.callee.done) return;
if(typeof jQuery!='undefined'){
jQuery.noConflict();
arguments.callee.done=true;
// do some jquery stuff i.e. jQuery('...').etc...
}
}
function waitForJQuery(){
if(typeof jQuery!='undefined'){
init();
return;
}
if(attemptCount<100){
setTimeout(waitForJQuery,100);
}
return;
}
if(document.addEventListener){
document.addEventListener("DOMContentLoaded",init,false);
}
else if(document.attachEvent){
waitForJQuery();
}
window.onload=init;任何帮助都将不胜感激。
发布于 2011-12-15 09:16:12
我认为jQuery需要在MooTools之前初始化,因为$是别名,jQuery有能力解除绑定,如果考虑到您的情况,可能值得一试。
<p>jQuery sets this paragraph's color to red but MooTools sets the border color.</p>
<script type="text/javascript" src="jquery-1.x.x.js"></script>
<script type="text/javascript">
//no conflict jquery
jQuery.noConflict();
//jquery stuff
(function($) {
$('p').css('color','#ff0000');
})(jQuery);
</script>
<script type="text/javascript" src="moo1.x.js"></script>
<script type="text/javascript">
//moo stuff
window.addEvent('domready',function() {
$$('p').setStyle('border','1px solid #fc0');
});
</script>发布于 2011-12-15 19:41:57
你使用的是什么工具版本?Mootools将“自动交出”$。
您有使用jQuery编写的$和mootools的代码吗?
如果是这样的话,您将需要在至少一种语言中手动查找美元签名的每一个实例,并替换为以下内容
对于jQuery $()变成jQuery()
对于Mootools $()变成document.id() // FYI,这是More中的首选编码模式,而且从1.3开始更多。
希望这能有所帮助!
如果完成此步骤,则不会出现冲突:)
发布于 2011-12-15 09:05:32
在这里,您可以尝试一种方法:
// Add jQuery
var GM_JQ = document.createElement('script');
GM_JQ.src = "http://jquery.com/src/jquery-latest.js";
GM_JQ.type = "text/javascript";
document.getElementsByTagName('head')[0].appendChild(GM_JQ);
// Check if jQuery's loaded.
function GM_wait() {
if(typeof unsafeWindow.jQuery == 'undefined') { window.setTimeout(GM_wait,100); }
else { $ = unsafeWindow.jQuery; letsJQuery(); }
}
GM_wait();
// All your GM code must be inside this function.
function letsJQuery() {
alert("cheers");
}https://stackoverflow.com/questions/8517300
复制相似问题