刷新div后保持打开多个div

时间:2014-08-28 16:59:49

标签: jquery refresh toggle jquery-cookie

我有点问题,我想保持div的风格"显示:阻止;"刷新div后。 我有一个保管箱菜单:

<div class="navigation-wrapper" id="menu_rep">
<div class="nav-item" id="zona_1">
    <a href="javascript:void(0);" class="submenu-item bedroom2-icon">MODULO A<em class="dropdown-item"></em></a>
                       <div class="submenu" style="display: none;">
                              <a href="javascript:void(0);" id="5 off" class="mini_ledoff-icon">POWER 1
                              <em class="unselected-item"></em>
                              </a>
                        </div>
                        <div class="submenu" style="display: none;">
                              <a href="javascript:void(0);" id="2 off" class="mini_ledoff-icon">POWER 2
                              <em class="unselected-item"></em>
                              </a>
                       </div>
                       <div class="submenu" style="display: none;">
                              <a href="javascript:void(0);" id="1 off" class="mini_ledoff-icon">POWER 3
                              <em class="unselected-item"></em>
                              </a>
                       </div>
                       <div class="submenu" style="display: none;">
                              <a href="javascript:void(0);" id="6 off" class="mini_ledoff-icon">POWER 4
                              <em class="unselected-item"></em>
                              </a>
                       </div>
</div>
<div class="nav-item" id="zona_2">
       <a href="javascript:void(0);" class="submenu-item bedroom-icon">MODULO B<em class="dropdown-item"></em></a>
                       <div class="submenu" style="display: none;">
                              <a href="javascript:void(0);" id="14 off" class="mini_ledoff-icon">POWER 1
                              <em class="unselected-item"></em>
                              </a>
                       </div>
                       <div class="submenu" style="display: none;">
                              <a href="javascript:void(0);" id="11 off" class="mini_ledoff-icon">POWER 2
                              <em class="unselected-item"></em>
                              </a>
                       </div>
                       <div class="submenu" style="display: none;">
                              <a href="javascript:void(0);" id="10 off" class="mini_ledoff-icon">POWER 3
                              <em class="unselected-item"></em>
                              </a>
                       </div>
                       <div class="submenu" style="display: none;">
                              <a href="javascript:void(0);" id="15 off" class="mini_ledoff-icon">POWER 4
                              <em class="unselected-item"></em>
                              </a>
                       </div>
</div>
</div> 

Jquery脚本:

<script>
$( document ).on( "tap", "a.mini_ledon-icon", function() {
  var cmd = ($(this).attr('id'));
  var p = cmd.split(" ");
  var off = p[0] +' off';
  $.post( "functions/sendcmd.php", { CMD: cmd } )
  $( this ).removeClass( "mini_ledon-icon" );
  $( this ).addClass( "mini_ledoff-icon" );
  $( this ).attr("id",off);
});
$( document ).on( "tap", "a.mini_ledoff-icon", function() {
  var cmd = ($(this).attr('id'));
  var p = cmd.split(" ");
  var on = p[0] +' on';
  $.post( "functions/sendcmd.php", { CMD: cmd } )
  $( this ).removeClass( "mini_ledoff-icon" );
  $( this ).addClass( "mini_ledon-icon" );
  $( this ).attr("id",on);
});
var isScrolling = false;
var lastScrollPos = 0;
var counter = 0;


$(function() {

    $('#menu_rep').on('scroll', function() {
        isScrolling = true;
        lastScrollPos = this.scrollTop;
    });

    $( document ).on( "click", ".submenu-item", function() {    
        $(this).parent().find('.dropdown-item').toggleClass('active-dropdown');
        $('.dropdown-item').not($(this).parent().find('.dropdown-item')).removeClass('active-dropdown');
        $(this).parent().find('.submenu').toggle(150);
        $('.submenu').not($(this).parent().find('.submenu')).hide();
        return false;
    });

    refreshTimer = setInterval(agg_menu, 10000);

    function agg_menu(){
        if (!isScrolling) {
           var referer = 'indoor.php #menu_rep';
            $("#menu_rep").load(referer);
        }
        isScrolling = false;
    }   
});
</script>

我尝试使用库cookie,但有些不对劲,有人可以帮我一把吗?

1 个答案:

答案 0 :(得分:0)

删除此行,它应该适合您。

$('.submenu').not($(this).parent().find('.submenu')).hide();