[英]JQuery Mobile to check if a Div is Expanded or Collapsed
I have a Div that is collapsible using attribute data-role="collapsible"
我有一个可以使用属性data-role="collapsible"
折叠的Div
How can I check at any point in time whether the Div is in Collapsed mode or Expanded mode. 如何在任何时间点检查Div是处于折叠模式还是扩展模式。 I tried this but it doesn't work: 我试过这个,但它不起作用:
if ($("#hideshow").is(":collapsed"))
alert("collapsed");
Please note that :visible
won't work because in both states visible returns true. 请注意:visible
不起作用,因为在两个状态中,visible返回true。
This is done via CSS. 这是通过CSS完成的。 When a collapsible element is collapsed, it has the class "ui-collapsible-collapsed" added. 折叠折叠元素时,会添加“ui-collapsible-collapsed”类。 Use .hasClass() to check it 使用.hasClass()来检查它
if ($("#hideshow").hasClass('ui-collapsible-collapsed')) {
alert("collapsed");
}
Use the getter of collapsed option for this: 使用折叠选项的getter:
if ($("#hideshow").collapsible("option", "collapsed")) { alert("collapsed"); }
Tested and working! 经过测试和工作!
if (metingblok.collapsible( "option", "collapsed") == false ) {
//then it is closed
}
if (metingblok.collapsible( "option", "collapsed") == true) {
//then it is open
}
Try to use: 尝试使用:
if ($("#hideshow").attr('data-role')=="collapsible")
alert("collapsed");
This will do the trick: 这样就可以了:
if ($("#hideshow").attr('data-role')=="collapsible") {
console.log("collapsed");
}
Instead of console.log
, enter whatever you wish as processing. 而不是console.log
,输入您希望处理的任何内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.