[英]jQuery conflict between scripts
I am using CakePHP and am using 2 javascript scripts one of which relies on jQuery. 我正在使用CakePHP并使用2个javascript脚本,其中一个依赖于jQuery。
On one of these javascripts the $ variable is used which conflicts with jQuery and thus 在其中一个javascripts中,使用了与jQuery冲突的$变量
I had to include the following bit of code in cakephp : 我必须在cakephp中包含以下代码:
<?php
$this->Js->JqueryEngine->jQueryObject = '$j';
print $this->Html->scriptBlock('var $j = jQuery.noConflict();', array('inline' => false));
?>
This made the javascript + jQuery inclusion work fine. 这使得javascript + jQuery包含工作正常。 I then wanted to add another javascript which requires jQuery - which I have however I get the following error:
然后我想添加另一个需要jQuery的javascript - 但我得到了以下错误:
Uncaught TypeError: Object function $(element) { if (arguments.length > 1) {
for (var i = 0, elements = [], length = arguments.length; i < length; i++)
elements.push($(arguments[i]));
return elements; } if (Object.isString(element))
element = document.getElementById(element); return Element.extend(element);} has no method 'extend'
I am not a massive javascript buff. 我不是一个庞大的javascript buff。 But this confuses me and obviously there is a conflict - please help me get this jQuery based script work.
但这让我感到困惑,显然存在冲突 - 请帮助我获得基于jQuery的脚本工作。
Thanks, 谢谢,
您需要使用在无冲突部分中定义的无冲突选择器,即$ j而不是简单的$。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.