我有一个包含多个 jqGrids 的页面,但一次只能看到一个。我想要一个简单的函数来返回哪个是随时可见的。有没有像这样的函数,它会显示哪些 div 是可见的:
$('div').each(function(){
if($(this).is(':visible')){
alert($(this).attr('id'));
}
});
是否有类似这样的东西可以解析页面上的所有 jqGrids?
谢谢!
最佳答案
你可能需要像下面这样的东西
$("table.ui-jqgrid-btable:visible").attr('id');
如果表格上没有网格,您将获得 undefined
值。如果可见多个网格,您将获得第一个网格的 ID。
要获得所有可见网格的 id 数组,您可以使用以下代码
var ids = $.map($("table.ui-jqgrid-btable:visible"), function(value) {
return value.id;
});
// now we have all ids in the array
alert(ids.join()); // display all as comma-separated
你可以通过 grid
expandos 的测试让上面的代码更安全:
var ids = $.map($("table.ui-jqgrid-btable:visible"), function(value) {
if (value.grid) { return value.id; }
});
// now we have all ids in the array
alert(ids.join()); // display all as comma-separated
关于javascript - 如何确定可见 jqGrid 网格的 ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10357106/