MooTools和jQuery冲突-尽管采用美元安全模式 [英] MooTools and jQuery conflict - despite Dollar Safe Mode

查看:80
本文介绍了MooTools和jQuery冲突-尽管采用美元安全模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使一些预先存在的MooTools代码在Drupal网站中正常运行.我知道MooTools代码可以独立运行.在页面中加载MooTools库后,jQuery停止运行.

I'm trying to get some pre-existing MooTools code to function properly within a Drupal site. I know the MooTools code works on its own. Once I load the MooTools library in the page, jQuery stops functioning.

我在jQuery之后加入MooTools,(根据MooTools开发人员的说法)应该可以防止Moo从已经加载的jQuery库中窃取已经定义的$.

I am including MooTools after jQuery, which (according to the MooTools developers) should prevent Moo from stealing the already defined $ from the already loaded jQuery library.

我已经将Moo代码中所有$的引用转换为document.id.

I've converted all references of $ within my Moo code to document.id.

当我加载页面时,Moo代码有效,但jQ代码无效.看来,Moo仍在从jQ手中窃取$变量,并为其重新定义.出于测试目的,我正在加载的Moo代码是一个简单的12手风琴脚本.如果解决了这个问题,我需要使用更复杂的软件.

When I load the page, the Moo code works but the jQ code does not. It appears that Moo is still stealing the $ variable away from jQ and redefining it for itself. For testing purposes, the Moo code I'm loading is a simple 12 Accordion script. There are more complex ones I need to use if I get this problem resolved.

Drupal广泛使用jQuery,因此使用jQ的no_conflict模式不是可行的选择.据我了解,考虑到美元安全模式,这应该是可能的.

Drupal makes extensive use of jQuery, so using jQ's no_conflict mode is not a viable option. From what I understand, this should be possible given Dollar Safe Mode.

我正在使用MooTools Core 1.2.4和MooTools More 1.2.4.4和jQuery 1.2.6(也尝试过1.4.2).

I'm using MooTools Core 1.2.4 and MooTools More 1.2.4.4 and jQuery 1.2.6 (also tried 1.4.2).

推荐答案

您始终可以使用jQuery()代替使用$访问jQuery函数.

Instead of using $ to access the jQuery functions you can always use jQuery().

使用.ready()时,您甚至可以传递自己的标识符,例如:

You can even pass your own identifier when using .ready(), example:

jQuery(document).ready(function(myIdentifier){

   myIdentifier(); // this is the jQuery reference!

});

这篇关于MooTools和jQuery冲突-尽管采用美元安全模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆