magento引入jquery库和prototype库冲突的解决办法

12 篇文章 0 订阅

对于jQuery自身不同版本的冲突问题,和jQuery和其他引入库的问题,我们可以参看   http://api.jquery.com/jQuery.noConflict/    来解决,在我使用的过程中遇到了jQuery库和prototype库的冲突的问题。

然后比较抵触使用其他符号替代jQuery当中的$符号,因而

This technique is especially effective in conjunction with the .ready() method's ability to alias the jQuery object, as within callback passed to .ready() you can use $ if you wish without fear of conflicts later:

1
2
3
4
5
6
7
8
9
     
     
<script src="other_lib.js"></script>
<script src="jquery.js"></script>
<script>
$.noConflict();
jQuery( document ).ready(function( $ ) {
// Code that uses jQuery's $ can follow here.
});
// Code that uses other library's $ can follow here.
</script>
即可。但是对于我写的onclick事件,不知为何系统不再响应了,所以

用这段代码替代了              

var loadmore = document.getElementById('loadMore');
                loadmore.addEventListener('click', function() {
                    $(".section1").css("height", "962px");
                    $(".section1").css("background-image", "url(http://www.annkestore.com/media/topic/20160120/haikan11big.jpg)");
                    $(".panel2").show();
                    $(".moreClick").hide();
                }, false);

急用addEventListenner替代onclick方法。

另外在stackoverflow上的这个地址http://stackoverflow.com/questions/7532124/jquery-prototype-conflicts-in-magento/7532172#7532172

找到了解决方法

If you want to include the jquery and no conflict code in your local.xml then use:

<default>
    <reference name="head">
        <block type="core/text" name="google.cdn.jquery">
            <action method="setText">
                <text><![CDATA[<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script><script type="text/javascript">jQuery.noConflict();</script>]]>
                </text>
            </action>
        </block>
    </reference>
</default>




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值