【发布时间】:2012-01-19 04:23:57
【问题描述】:
如果我有一个在悬停时显示和隐藏元素的 jquery 脚本,如何让我应该隐藏的元素在单击时保持显示?
$(selector).hover(function(){
//this shows the element on mousein
$(element).show();
$(element).click(function(){
$(this).css({'display':'list-item'});
});
},function(){
//this hides element on mouseout
$(element).hide();
}
它的列表项的原因是因为我单击的这个元素是<li> 标记。我相信这就是为什么它应该是list-item 而不是block?另外,当我在 click 函数中执行 alert($(element).css('display')); 时,它会显示列表项。
【问题讨论】:
-
您在每次悬停时添加点击处理程序...代码应类似于:
$(selector).hover(function(){...}, function(){...}).click(function(){...});
标签: jquery function click hover show-hide