本文介绍了jQuery .toggle(showOrHide)不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用.toggle(showOrHide)函数检查状态.在api文档中,它被称为;

I want to use .toggle( showOrHide ) function to check the status. In the api documentation, it is mentioned as;

$( "#foo" ).toggle( showOrHide );
if ( showOrHide === true ) {
    $( "#foo" ).show();
} else if ( showOrHide === false ) {
    $( "#foo" ).hide();
}

但是它不起作用.有人知道如何使它起作用吗?我想检查其状态是显示还是隐藏.

But its not working. Anybody knows how to make it work? I want to check the status whether its show or hide.

推荐答案

根据文档: http://api.jquery.com/toggle/

您需要声明truefalse;

var showOrHide = true;

if ( showOrHide === true ) {
    $( "#foo" ).show();
} else if ( showOrHide === false ) {
    $( "#foo" ).hide();
}

在大多数情况下,使用速记是有意义的,但是OP似乎需要先检查状态.

Using the shorthand would make sense in most cases, but it seems the OP has a requirement to check the status first.

这篇关于jQuery .toggle(showOrHide)不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 21:34