1

我的 HTML 文件中有两个$(document).ready(function($)函数。现在因为有两个ready()函数,所以只有一个执行!由于我对 jQuery 不太了解,因此无法合并它们。

<script type="text/javascript">

    $(document).ready(function($){

        $('#mega-1').dcVerticalMegaMenu({
            rowItems: '3',
            speed: 'fast',
            effect: 'show',
            direction: 'right'
        });
        $('#mega-2').dcVerticalMegaMenu({
            rowItems: '3',
            speed: 'slow',
            effect: 'fade',
            direction: 'left'
        });
        $('#mega-3').dcVerticalMegaMenu({
            rowItems: '4',
            speed: 'slow',
            effect: 'slide',
            direction: 'right'
        });
        $('#mega-4').dcVerticalMegaMenu({
            rowItems: '3',
            speed: 'fast',
            effect: 'slide',
            direction: 'left'
        });

    });
    </script>

jQuery函数2:

<script type="text/javascript">
    $(document).ready(function(){
        $("#featured > ul").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 5000, true);
    });
</script>
4

1 回答 1

1
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Page Title</title>

<script src="some_javascript_file.js"></script>
<script src="another_js_file.js"></script>

</head>
<body>

<!-- HTML HERE -->


<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="jQuery_plugin_1.js"></script>
<script src="jQuery_plugin_2.js"></script>
<script>
(function($){ // remap $ to jQuery

    $(function(){
        $('#mega-1').dcVerticalMegaMenu({
            rowItems: '3',
            speed: 'fast',
            effect: 'show',
            direction: 'right'
        });
        $('#mega-2').dcVerticalMegaMenu({
            rowItems: '3',
            speed: 'slow',
            effect: 'fade',
            direction: 'left'
        });
        $('#mega-3').dcVerticalMegaMenu({
            rowItems: '4',
            speed: 'slow',
            effect: 'slide',
            direction: 'right'
        });
        $('#mega-4').dcVerticalMegaMenu({
            rowItems: '3',
            speed: 'fast',
            effect: 'slide',
            direction: 'left'
        });


        // =====================================

        $("#featured > ul").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 5000, true);

    });

})(jQuery);
</script>

</body>
</html>
于 2012-07-17T11:48:51.463 回答