Convert jQuery code to mootools 1.11

巧了我就是萌 提交于 2019-12-24 10:46:37

问题


I use a slideshow which needs mootools 1.11 and my other code needs jQuery. Unfortunately as soon as I call the jquery library the slideshow is crashing.

Can I convert this little jquery code in to moo tools or pure javascript? How would the mootools code look like?

jQuery(document).ready(function(jQuery) {
    jQuery('.rgstitle, .rgsdescription').click(function(event) {
        window.open(jQuery('#rgslideshow-4574 a img:visible').parent().attr('href'), '_self');    
        return false;
    });
});

Thanks a lot!


回答1:


Leave the '$' for your mootools based code as it is. And Use 'jQueryDollar' for your jQuery codes. After adding the jquery library, use this :

<script src="jquery.js"></script>
<script>
var jQueryDollar = jQuery.noConflict();
// Do something with 'jQueryDollar'
jQueryDollar(document).ready(function(jQueryDollar) {
    jQueryDollar('.rgstitle, .rgsdescription').click(function(event) {
        window.open(jQueryDollar('#rgslideshow-4574 a img:visible').parent().attr('href'), '_self');    
        return false;
    });
});
</script>

Now add mootools libraries just beneath:

 <script src="mootools.js"></script>
 <script>
     //'$' is now free for mootools
 </script>



回答2:


Here's a simple fix if you want the 2 libraries to work toghether. Put the following right after jQuery.js script tag

<script type="text/javascript">
 jQuery.noConflict();
</script>



回答3:


Its better to check, Avoiding Conflicts with Other Libraries article from Jquery team. I got the same problem and Solved jQuery slider and mootool news ticker :D



来源:https://stackoverflow.com/questions/9597442/convert-jquery-code-to-mootools-1-11

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!