Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想检查我的子网格是否存在(已扩展)。
我想这样做是因为我想用一个按钮将所有更改的数据保存在我的网格和所有子网格中。但是并不总是扩展每个子网格(我将在两次迭代中执行此操作) - 所以我必须检查子网格是否存在以保存它。
我试过
if(jQuery("#example").grid) { ... }
和
if(jQuery("#example")) { ... }
但是这些语句的输出始终是“未定义的”。网格名称绝对是正确的 - 我只是在这里写了#example ;-)
谢谢!!
当你想查找一个元素是否存在 jQuery 对象的测试长度
if(jQuery("#example").length) { /* element with ID=example exists*/ }
您提到expanded但没有说明 html 示例或解释如何expanded工作。
expanded
另请注意,ID 不能在页面中重复。如果您有重复的 ID,肯定需要查看 html 以便为遍历创建更好的解决方案。我提到这一点是因为引用了多个子网格和一个 ID 选择器被用作示例代码