jQuery .toggle()无法与第二个函数正常工作? [英] jQuery .toggle() not working as expected with second function?
问题描述
我正在尝试创建一个按钮来显示/隐藏其下方的div,一切正常,我只是在挣扎最后一刻!
I'm trying to create a button to show / hide a div below it, all is working fine, I'm just struggling with the last bit!
我需要区分是显示还是隐藏动作,以便可以将变量传递到其他地方,这就是我所拥有的.
I need to distinguish wether it's a show or hide action so I can pass the variable elsewhere, here's what I have..
$(this).find('.hide-close').click(
function() {
$(this).siblings('.dragbox-content').toggle(function() {
alert($(this).parent().attr("id") + ' Show');
},function() {
alert($(this).parent().attr("id") + ' Hide');
}
);
})
.end()
});
如果使用以下代码,去掉toggle()中的第二个函数,它起作用吗?但是然后我没有显示/隐藏变量.
If use the following code, taking out the second function within toggle(), it works?! But then I don't have a show / hide variable.
$(this).find('.hide-close').click(
function() {
$(this).siblings('.dragbox-content').toggle(function() {
alert($(this).parent().attr("id") + ' Show');
}
);
})
.end()
});
预先感谢您的帮助,希望这真的很简单,我只是看不到! :)
Thanks in advance for any help, hopefully it's something really simple I just can't see! :)
推荐答案
您可以在函数内部使用$(this).is(":visible")
来检查其是否可见.
You can use $(this).is(":visible")
inside the function to check whether its visible or not.
这篇关于jQuery .toggle()无法与第二个函数正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!