使用Jquery原型

扫码查看
本文介绍了使用Jquery原型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用原型与Jquery共存。



我的意思是不是Jquery的原型与Jquery NoConflict标签,但反过来。



我必须覆盖原型实用程序方法才能与其他库共存?



我无法控制Jquery脚本

解决方案

当包含jQuery时,它会获取任何定义为 $ 并存储对它的引用。当你使用 jQuery.noConflict 时,它会恢复该引用,并返回 jQuery ,它允许你重命名jQuery。 / p>

如果你想重命名Prototype,那应该是完全可能的。

  // 1. include原型
// $ ==原型
// 2. include jQuery
// $ == jQuery

var jq = jQuery。 noConflict();
var $ p = $;
$ = jq;

//现在,$ == jQuery
//和$ p ==原型


Is there any way of using prototype to coexist with Jquery.

What i mean is not Jquery with prototype with the Jquery NoConflict tag but the other way around.

I have to override prototypes utility methods to coexist with other libraries?

I have no control over the Jquery Scripts

解决方案

When jQuery is included, it takes a copy of whatever is defined as $ and stores a reference to it. When you use jQuery.noConflict it restores that reference, and returns jQuery which allows you to "rename" jQuery.

If you want to rename Prototype, that should be entirely possible.

// 1. include Prototype
//    $ == Prototype
// 2. include jQuery
//    $ == jQuery

var jq = jQuery.noConflict();
var $p = $;
$ = jq;

// now, $ == jQuery
// and $p == Prototype

这篇关于使用Jquery原型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 17:09
查看更多