【发布时间】:2012-09-25 02:08:52
【问题描述】:
我正在尝试实现 div 隐藏如果用户单击除元素之外的任何位置。如果用户单击按钮,我将执行toggle() 的以下代码。如果Details 元素可见,我希望按钮单击保持加号,并对屏幕的其他部分做出反应。
$('.nav-toggle').click(function() {
//get collapse content selector
var collapse_content_selector = $(this).attr('href');
//make the collapse content to be shown or hide
var toggle_switch = $(this);
$(collapse_content_selector).toggle(function() {
if ($(this).css('display') == 'none') {
//change the button label to be 'Show'
toggle_switch.html('Show Details');
} else {
//change the button label to be 'Hide'
toggle_switch.html('Hide Details');
}
});
});
【问题讨论】:
-
我可能没有很好地解释自己。看看这个小提琴jsfiddle.net/planxdesign/b9mLB/1这是我目前得到的代码,我想隐藏#details-window,以防用户点击“隐藏详细信息”或/和其他任何地方导航箭头。
标签: javascript jquery