开发者

jQuery Slide Menu in Master Page

开发者 https://www.devze.com 2023-03-18 07:10 出处:网络
I have a ASP.NET custom server control menu with the following jQuery in the head of the master page. The problem is that when I have a button on a regular form it causes the slide action in the side

I have a ASP.NET custom server control menu with the following jQuery in the head of the master page. The problem is that when I have a button on a regular form it causes the slide action in the side menu in the master page to activate every time it is clicked in the form... how can I prevent this so that the slide action only happens on initial page load or when a different men item is clicked?

$(document).ready(function() {
    // Expand/Collapse All
    $('#example1 .expand_all').click(function() {
        $('#menu1 > li > a.collapsed').addClass('expanded').removeClass('collapsed').parent().find('> ul').slideDown('medium');
    });
    $('#example1 .collapse_all').click(function() {
        $('#menu1 > li > a.expanded').addClass('collapsed').removeClass('expanded').parent().find('> ul').slideUp('medium');
    });
    // Slide
    $("#menu1 > li > a.expanded + ul").slideToggle("medium")开发者_如何学Go;
    $("#menu1 > li > a").click(function() {
        $(this).toggleClass("expanded").toggleClass("collapsed").parent().find('> ul').slideToggle("medium");
    });
});


Have you tried using .one()? Maybe this will help: .one()

Edit: I'm not sure if this is the best way to solve this:

<asp:HiddenField ID="isloaded" runat="server" Value="false" EnableViewState="true" />

$(document).ready(function () {
    var isLoaded = document.getElementById("isloaded").value;
    if (isLoaded == "false") {
        //your code
        document.getElementById("isloaded").value = "true";
    }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消