1

我在下面有一段代码显示 div 并将其存储在 cookie 中,如果 cookie 存在,它会隐藏它们。问题是当我将我的 3 秒延迟添加到其中一个 div id 时,当页面重新加载 id 时延迟不断出现

    <script type="text/javascript" >
  //Search script to hide
   $(document).ready(function(){
     $('#popUpsearch').effect("pulsate", { times:2 }, 4000);
    $('#popUpsearch').fadeOut(5000); 

       $('#popUpsearch').load('a', function() {
         $.cookie('contentsearch','hid', { expires: 365});
     });

       if ( $.cookie('contentsearch') == 'hid'){
   $('#popUpsearch').hide();    
      };    
  $('#popUpnav').delay(3000).effect("pulsate", { times:2 }, 4000)
    $('#popUpnav').fadeOut(6000);
     $('#popUpnav').load('a', function() {
         $.cookie('contentnav','hide', { expires: 365});
     });
      if ( $.cookie('contentnav') == 'hide'){
     $('#popUpnav').hide();    
    };  
}); 

    //$(function() {
//   $.cookie('searchbox','sb3', { expires: 365});
//        if ($.cookie('searchbox') == 'sb3'){
//           $('#popUpsearch').hide();    
//        };    
//    }); 

</script>
4

1 回答 1

0

使用您的 If 块,以便您一次只执行一组操作。

if ( $.cookie('contentnav') == 'hide'){
  $('#popUpnav').hide();    
} else {
 $('#popUpnav').delay(3000).effect("pulsate", { times:2 }, 4000)
 $('#popUpnav').fadeOut(6000);
 $('#popUpnav').load('a', function() {
   $.cookie('contentnav','hide', { expires: 365});
 });
}
于 2013-02-07T03:39:18.080 回答