如何使用jquery.noConflict属性

问题描述:

我正在使用预览DNS在服务器上测试我的网页.刚刚意识到,预览dns会在任何php页面的末尾自动添加mootools库.可能是他们自己的统计信息或其他信息.

I am testing my webpage on a server using preview dns. Just realized that preview dns automatically adds mootools library towards the end of any php page. Probably for their own statistics or something.

但是问题是我在页面中使用了jquery.所以我的jquery代码中断了,因为mootools和jquery都使用"$".

But the problem is that I am using jquery in my page. So My jquery code breaks because both mootools and jquery both use '$'.

我已将页面的所有页面源都放在jsbin上: http://jsbin.com/ozime(包括在mootools上添加的内容).

I've put all the page source of my page on jsbin: http://jsbin.com/ozime (this includes the added on mootools).

在此页面中,我添加了一个示例jquery代码,该代码应在下拉框更改时触发.我还添加了一些警报语句.但是,仅显示第一个警报声明.一个内部jquery代码没有.

In this page I've added a sample jquery code which should trigger on change of the drop down box. I added some alert statements as well. However, only first alert statement shows up. One inside jquery code does not.

我尝试使用jquery时没有冲突,但是它似乎不起作用.

I've tried to use jquery no conflict but it does not seem to work.

有人遇到过这个问题吗?

Has someone faced this issue?

在包含jQuery之后,在脚本标记后立即添加以下内容.

After you include jQuery, add the following in a script tag immediately after it.

<script> 
jQuery.noConflict();

jQuery(document).ready(function() {
alert('hi');
});
</script>

也将jQuery脚本放在mootools库之前.订单将是:

Also place your jQuery script before your mootools library. Order will be:

jQuery脚本包含

jQuery script include

noConflict代码

noConflict code

mootools脚本包括

mootools script include