首页 \ 问答 \ JQuery - 重置切换状态(JQuery - reset toggle state)

JQuery - 重置切换状态(JQuery - reset toggle state)

我有一个按钮,当切换显示/隐藏一个div('.reportOptions'),这工作得很好。

$('.reportOptions').click(function(e){ 
   e.stopPropagation();
});


$('.requestOptions').toggle(
   function(){
      $(this).parent().find('.reportOptions').css('display','block');   //show request options
   },function(){
      $('.reportOptions').css('display','none');    //hide all request oprtions menus
   }
);

通过执行以下操作,同样的div也可以通过点击来隐藏

$(document).click(function(){
   $('.reportOptions').css('display','none');
   $('.requestOptions').toggle(even);
});

我使用最后一个函数的问题是,如果执行它,我必须双击resuestOptions按钮才能再次显示div。

我想知道的是,是否有任何方法可以在不必更改切换功能的情况下重置切换状态。


I have a button which when toggled displays/hides a div ('.reportOptions'), this works perfectly fine.

$('.reportOptions').click(function(e){ 
   e.stopPropagation();
});


$('.requestOptions').toggle(
   function(){
      $(this).parent().find('.reportOptions').css('display','block');   //show request options
   },function(){
      $('.reportOptions').css('display','none');    //hide all request oprtions menus
   }
);

the same div can also be hidden by clicking away from it by doing the following

$(document).click(function(){
   $('.reportOptions').css('display','none');
   $('.requestOptions').toggle(even);
});

the problem I have with the last function is that if it is performed I must double click the resuestOptions button in order to display the div again.

What I want to know is if there is any way in which you can reset the toggle state without having to change the toggle function.


原文:https://stackoverflow.com/questions/9879023
更新时间:2023-12-01 11:12

最满意答案

您可以查看像Shadowbox这样的JavaScript工具,它可以将任何类型的元素加载到网站上方的框中。


You can look at javascript tools like Shadowbox that can load any types of elements into a box above the site.

相关问答

更多
  • 将SWF嵌入HTML页面的最佳方法是使用SWFObject 。 它是一个简单的开源JavaScript库,易于使用和标准友好的嵌入Flash内容的方法。 它还提供Flash播放器版本检测。 如果用户没有Flash版本或禁用JavaScript,他们将看到一个替代内容。 您也可以使用此库来触发Flash Player升级。 一旦用户升级,它们将被重定向回到页面。 文档的一个例子:
  • 一旦你的尺寸正常工作,你需要将wmode设置为透明 ,以便能够看到闪光灯背后的内容,如果不这样,它的背景将是不透明的。 这是来自swfobject文档的快速copypaste,但它应该得到重点: