检查隐藏是否等于true或false jQuery [英] check if hidden equals true or false jQuery
本文介绍了检查隐藏是否等于true或false jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个
$('#div')。attr(hidden,true);
我试过了:
var a = $('#div')。attr(hidden);
var b = $('#div')。attr(hidden)。val();
var c = $('#div')。hidden;
var a = $('#div')。disabled;
我只想知道隐藏是真是假。有人知道吗?我的研究结果都是关于表单和输入的。
解决方案
属性永远不会是 true
,它只能包含字符串。
jQuery包含字符串之外的其他对象的 data
函数:
$('#div')。data(hidden,true); //设置隐藏数据
var flag = $('#div')。data(hidden); //获取隐藏数据(true)
如果要隐藏 div
,使用 .hide()
:
$( '#DIV')隐藏()。
然后检查div是否可见:visible
$('#div' )。是( ':可见'); //或$('#div')。is(':hidden')
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.
解决方案
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')
这篇关于检查隐藏是否等于true或false jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文