【问题标题】:how to remove jQuery conflict in Magento 1.8 [closed]如何在 Magento 1.8 中删除 jQuery 冲突 [关闭]
【发布时间】:2015-11-21 19:48:58
【问题描述】:

朋友们,我已经在注册页面和编辑页面上编写了我的 javascript,但在我的编辑页面上我发现了两个错误。 在 magento 1.8 中。我在 layout/page.xml 中添加了 noconflict 但我没有得到任何解决方案。

TypeError: element.attachEvent is not a function
http://localhost/cdd_chile/js/prototype/prototype.js
Line 5653

TypeError: element.dispatchEvent is not a function
http://localhost/cdd_chile/js/prototype/prototype.js
Line 5734

我在两个页面上都使用这些脚本.....

<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);?>cddjs/jquery.Rut.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />

【问题讨论】:

    标签: javascript jquery magento-1.8


    【解决方案1】:

    像使用 jquery 的 noConflict() 一样

    $.noConflict();
    

    例如。

    <script type="text/javascript" src"jquery-1.11.js"></script>
        <script type="text/javascript"> 
            $j = jQuery.noConflict(true); 
     </script> 
    

    $j 现在是访问 jquery 的新别名。它已经覆盖了您的 $ 别名。在包含 jQuery 或其他要解决冲突的插件之后,您立即包含 noConflict。如需更多解释请看here

    编辑:示例

    <html>
    <head>
    <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
      <script type="text/javascript"> 
            $j = jQuery.noConflict(true); 
    
            $j(document).ready(function(e){     
                $j("#test").click(function(){
                     alert("hi");
                });
            });
     </script> 
    
    </head>
    <body>
    <button id="test" type="button">Say Hi</button>
    </body>
    </html>
    

    【讨论】:

    • 嗨,Akki,你能告诉我究竟是哪个地方添加了 $.noConflict();因为我试过但它不起作用....
    • 但它不起作用。怎么办?
    • 创建新错误 TypeError: $.validator is undefined localhost/cdd_chile/index.php/customer/account Line 389
    【解决方案2】:

    你可以使用:

    var jQuery = $.noConflict();
    

    jQuery 将是您的 jQuery 库的别名。

    $.noConflict() 将解决当您在任何其他库中有“$”时可能出现的任何冲突。

    【讨论】:

    猜你喜欢
    • 2011-12-30
    • 1970-01-01
    • 2013-11-26
    • 1970-01-01
    • 2017-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多