问题
i've got this
$('#div').attr("hidden", true);
i tried:
var a = $('#div').attr("hidden");
var b = $('#div').attr("hidden").val();
var c = $('#div').hidden;
var a = $('#div').disabled;
i just want to know whether hidden is true or false. does anybody know? my research results are all about forms and inputs.
回答1:
attribute will never be true
, it can have strings only.
jQuery has the data
functions for objects other than strings:
$('#div').data("hidden", true); // set the "hidden" data
var flag = $('#div').data("hidden"); // get the "hidden" data (true)
If you wanted to hide the div
, use .hide()
:
$('#div').hide();
And you check if the div is visible with :visible
\ :hidden
$('#div').is(':visible'); // Or $('#div').is(':hidden')
回答2:
i think you mean jquery visible
.is(':visible')
回答3:
Alternatively you could use
$('#div').toggle(showOrHide);
where showOrHide is a bool of true of false to hide or show.
This is the same as doing
if ( showOrHide == true ) {
$('#div').show();
} else if ( showOrHide == false ) {
$('#div').hide();
}
Hope this helps
来源:https://stackoverflow.com/questions/10008312/check-if-hidden-equals-true-or-false-jquery