我有以下代码,可以在单击链接时显示/隐藏(切换)div:
$('#complete-services-link').toggle(
function () {
$('#complete-services-box').fadeIn('fast');
},
function () {
$('#complete-services-box').fadeOut('fast');
}
);
#complete-services-box
是正在显示/隐藏的div,通常您会再次单击链接以关闭该框,但如果我这样做,则您可以单击该框以关闭它,然后单击切换链接,我将不得不双击它,因为该链接正在侦听第二个函数
$('#complete-services-box').fadeOut('fast');
$('#complete-services-link').toggle(
function () {
$('#complete-services-box').fadeIn('fast');
},
function () {
$('#complete-services-box').fadeOut('fast');
$('#complete-services-box').click(function () {
$('#complete-services-box').fadeOut('fast');
});
}
);