jQuery noConflict()问题 [英] jQuery noConflict() problem

查看:133
本文介绍了jQuery noConflict()问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在开发一个平台,每次页面加载时注入jQuery-1.2.6。我开发了我的页面来使用jQuery-1.4.2,所以当我的页面加载时,我的页面上有2个jQuery实例。

为了避免任何冲突,我的JS文件中的以下行在我的页面外:

  var mc $ = jQuery.noConflict(); 
jQuery(函数($)

如果我使用mc $ for

我在Firebug和IE中遇到了一个错误,我不知道如何解决。



在开发人员完成页面加载时,在平台上注入的文件中:

  $(文档).ready(函数(){

和Firebug中的错误状态:'$ is not a函数'。



这个错误只有在我做了以下更改后才会显示出来:

  var mc $ = jQuery.noConflict(); 

通过创建mc $变量来解决开发人员的$(document)...调用,如果是这样,我不知道如何解决这个问题,如果没有,我希望有一个解决方案,将功能提供回开发者的注入文件。

谢谢!


< head> 部分中的呼叫订单必须是下一个:


  1. jQuery库№1;
  2. no conflict;
  3. jQuery库№2 。

.noConflict()可以像这样:

 < script type =text / javascript> var mc $ = jQuery.noConflict();< / script> 

在脚本中使用此语法之后:

  MC $( '#容器')的高度(); 


So I'm developing on a platform that injects jQuery-1.2.6 every time when a page loads. I developed my page to use jQuery-1.4.2, so when my page loads there are 2 jQuery instances on my page.

To avoid any conflict, I've included the following line in my JS file that is outside my page:

var mc$ = jQuery.noConflict();
jQuery(function($)

Everything seems to be working if I use mc$ for where the $ was originally used.

I am getting an error in Firebug and IE that I don't know how to resolve.

Within a file that is injected on the platform when my page loads the developer has done:

 $(document).ready(function() {

and the error in Firebug states: '$ is not a function'.

This error only started to show up once I made the change of:

var mc$ = jQuery.noConflict();

I'm thinking that by creating the mc$ variable that something broke with the developer's $(document)... call. If so, I don't know how to resolve this and if not I would hope there is a solution that I can put into place to provide the functionality back to the developer's injected file.

Thanks!

解决方案

A call order in your <head> section must be next:

  1. jQuery library №1;
  2. noConflict for it;
  3. jQuery library №2.

.noConflict() can look like this:

<script type="text/javascript">var mc$ = jQuery.noConflict();</script>

And after use this syntax in the scripts:

mc$('#container').height();

这篇关于jQuery noConflict()问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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