Jquery Mootools conflict
Jquery Mootools conflict
可能的重复项:
jQuery和MooTools冲突
我在这里遇到了一些麻烦,如果尚未加载 jQuery 以运行我的脚本,我正在加载它。我的脚本入到别人网站的正文标签中的某个地方。我的问题是jquery通过加载它(jquery(与mootools冲突。
这是我的脚本:
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;
任何帮助将不胜感激。
我相信
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>
来源: http://davidwalsh.name/jquery-mootools
你用的是什么庵呵软件版本?Mootools将"自动放弃"美元。
您是否有使用 $ 编写的 jQuery 和 mootools 代码?
如果是这样,您将需要手动查找至少一种语言的美元符号实例,并替换为以下内容
对于 jQuery $(( 变为 jQuery((
对于 Mootools $(( 变为 document.id((仅供参考,这是自 1.3 以来 moo Core 和更多内容中的首选编码模式
希望这有帮助!
PS 如果您完成此步骤,则不会有冲突:)
这里有一种方法可以尝试:
// 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");
}
相关文章:
- geolocation-marker.js conflict with markerclusterer.js
- Mootools:如何在点击时保持元素高亮显示并停止所有事件
- javascript mootools平滑滚动'x'像素数量
- DOMDocument getelementbyid conflict?
- jQuery UI and Fuel UX conflict
- jQuery 1.6 and 1.7 Conflict
- mootools getElements failed
- mootools到窗体的QueryString
- mootools表单json post请求
- CSS conflict Liferay
- Mootools Asset with
- mootools点击:继电器没有在ipad/iphone上启动
- mootools 1.4.2和angular 1.3在ie8中配合得很好
- Mootools Selector issue
- mootools类型的函数将文本作为函数执行
- Mootools:拒绝设置不安全的标头“;连接”;
- 如何将对象引用传递到 mootools 中另一个对象的构造函数中
- Javascript Conflict (mootools, jquery_notification)
- Jquery Mootools conflict
- MooTools / LinkedIn JS (jQuery?) conflict