Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/446.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在asp.net应用程序中使用css和javascript菜单?_C#_Javascript_Html_Asp.net_Css - Fatal编程技术网

C# 如何在asp.net应用程序中使用css和javascript菜单?

C# 如何在asp.net应用程序中使用css和javascript菜单?,c#,javascript,html,asp.net,css,C#,Javascript,Html,Asp.net,Css,嗨,我想在我的asp.net应用程序中测试一个菜单,但我遇到了一个javascript错误 这里是我的aspx: <nav id="cbp-hrmenu" class="cbp-hrmenu"> <ul> <li> <a href="#">Products</a> <div class="cbp-hrsub"> <d

嗨,我想在我的asp.net应用程序中测试一个菜单,但我遇到了一个javascript错误

这里是我的aspx:

<nav id="cbp-hrmenu" class="cbp-hrmenu">
    <ul>
        <li>
            <a href="#">Products</a>
            <div class="cbp-hrsub">
                <div class="cbp-hrsub-inner">
                    <div>
                        <h4>Learning & Games</h4>
                        <ul>
                            <li><a href="#">Catch the Bullet</a></li>
                            <li><a href="#">Snoopydoo</a></li>
                            <!-- ... -->
                        </ul>
                    </div>
                    <div>
                        <h4>Utilities</h4>
                        <ul>
                            <li><a href="#">Gadget Finder</a></li>
                            <li><a href="#">Green Tree Express</a></li>
                            <li><a href="#">Green Tree Pro</a></li>
                            <li><a href="#">Wobbler 3.0</a></li>
                            <li><a href="#">Coolkid</a></li>
                        </ul>
                    </div>
                    <div>
                        <!-- ... -->
                    </div>
                </div><!-- /cbp-hrsub-inner -->
            </div><!-- /cbp-hrsub -->
        </li>
        <li><!-- ... --></li>
        <li><!-- ... --></li>
        <!-- ... -->
    </ul>
</nav>
下面是javascript:

var cbpHorizontalMenu = (function() {

    var $listItems = $( '#cbp-hrmenu > ul > li' ), //<--error $listItems is undefine
        $menuItems = $listItems.children( 'a' ),
        $body = $( 'body' ),
        current = -1;

    function init() {
        $menuItems.on( 'click', open );
        $listItems.on( 'click', function( event ) { event.stopPropagation(); } );
    }

    function open( event ) {

        if( current !== -1 ) {
            $listItems.eq( current ).removeClass( 'cbp-hropen' );
        }

        var $item = $( event.currentTarget ).parent( 'li' ),
            idx = $item.index();

        if( current === idx ) {
            $item.removeClass( 'cbp-hropen' );
            current = -1;
        }
        else {
            $item.addClass( 'cbp-hropen' );
            current = idx;
            $body.off( 'click' ).on( 'click', close );
        }

        return false;

    }

    function close( event ) {
        $listItems.eq( current ).removeClass( 'cbp-hropen' );
        current = -1;
    }

    return { init : init };

})();

我必须做的事情:

您是否已将CSS添加到ASP.NET应用程序中

<link rel="stylesheet" runat="server" media="screen" href="~/css/styles.css" />
我还注意到您正在使用jQuery库,您可能没有包括它。把它也放在你的标签里


如果您使用的是jQuery-请不要在变量名中使用$。$'cbp hrmenu>ul>li'是jQuery语法,因此您似乎正在使用jQuery或其他使用类似语法的库。您也在使用jQuery函数,比如on和removeClass,所以我很确定它是jQuery。我猜$is undefined可能是您的错误?尝试加载jQuery。或者告诉我们错误是什么。
<head runat="server">
<script src="FileName.js" type="text/javascript"></script>
</head>
<script type="text/javascript"src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>