Jquery 是 class 上的(“:可见”)
Jquery is(":visible") on a class
目前我正在这样做:
bl = !$("#divModal1").is(":visible") &&
!$("#divModal2").is(":visible") &&
!$("#divModal3").is(":visible") &&
!$("#divModal4").is(":visible") &&
!$("#divModal5").is(":visible");
其中 divModal# 是共享相同 class 的所有 div class="divModalDialog".
是否有更好的方法通过检查 class 而不是每个单独的一个来做到这一点?
如果显示其中一个或多个 divModal#,基本上 bl 必须为 false。
来自 .is
文档:
Check the current matched set of elements against a selector, element,
or jQuery object and return true
if at least one of these elements
matches the given arguments.
因此,只需使用 class 名称就足够了,因为如果其中任何一个可见,.is(":visible")
将 return 为真。
bl = !$(".divModalDialog").is(":visible");
:visible
伪class可用于获取可见元素。
bl = ! $(".divModalDialog:visible").length > 0
如果你想检查是否所有 divs
都不是 visible
你可以这样做:
var modalDialogsCount = $(".divModalDialog").length;
var returnValue = modalDialogsCount == !$(".divModalDialog:visible").length ? true : false;
此代码检查是否所有 divModalDialog
都不是 visible
并且 returns true
是否为真。
目前我正在这样做:
bl = !$("#divModal1").is(":visible") &&
!$("#divModal2").is(":visible") &&
!$("#divModal3").is(":visible") &&
!$("#divModal4").is(":visible") &&
!$("#divModal5").is(":visible");
其中 divModal# 是共享相同 class 的所有 div class="divModalDialog".
是否有更好的方法通过检查 class 而不是每个单独的一个来做到这一点?
如果显示其中一个或多个 divModal#,基本上 bl 必须为 false。
来自 .is
文档:
Check the current matched set of elements against a selector, element, or jQuery object and return
true
if at least one of these elements matches the given arguments.
因此,只需使用 class 名称就足够了,因为如果其中任何一个可见,.is(":visible")
将 return 为真。
bl = !$(".divModalDialog").is(":visible");
:visible
伪class可用于获取可见元素。
bl = ! $(".divModalDialog:visible").length > 0
如果你想检查是否所有 divs
都不是 visible
你可以这样做:
var modalDialogsCount = $(".divModalDialog").length;
var returnValue = modalDialogsCount == !$(".divModalDialog:visible").length ? true : false;
此代码检查是否所有 divModalDialog
都不是 visible
并且 returns true
是否为真。