jQuery 与菜单冲突



我正在处理一个有jQuery冲突错误的网站。我尝试了互联网上的一些练习,但我总是失败。请看一下脚本并教我如何解决此错误。

/**

 * navigation.js

 *

 * Handles toggling the navigation menu for small screens.

 */

( function() {

    var container = document.getElementById( 'site-navigation' ),

        button    = container.getElementsByTagName( 'h1' )[0],

        menu      = container.getElementsByTagName( 'ul' )[0];


    if ( undefined == button || undefined == menu )

        return false;


    button.onclick = function() {

        if ( -1 == menu.className.indexOf( 'nav-menu' ) )

            menu.className = 'nav-menu';


        if ( -1 != button.className.indexOf( 'toggled-on' ) ) {

            button.className = button.className.replace( ' toggled-on', '' );

            menu.className = menu.className.replace( ' toggled-on', '' );

            container.className = container.className.replace( 'main-small-navigation', 'navigation-main' );

        } else {

            button.className += ' toggled-on';

            menu.className += ' toggled-on';

            container.className = container.className.replace( 'navigation-main', 'main-small-navigation' );

        }

    };


    // Hide menu toggle button if menu is empty.

    if ( ! menu.childNodes.length )

        button.style.display = 'none';

} )();

谢谢:)

你需要在末尾添加"jQuery":

jQuery.noConflict();
(function( $ ) {
    // Your jQuery code here, using the $
})( jQuery );

取自: http://learn.jquery.com/using-jquery-core/avoid-conflicts-other-libraries/

试试这个。

$j = jQuery.noConflict();

现在在需要使用jQuery的地方使用$j。

例如,在任何需要jQuery的地方使用jQuery代码j$(...)。

最新更新