如何使用 javascript 检测特定页面加载?
我有一个画廊页面,其中有一个带有 id 的表。每个表格单元格都有一个 img 元素。如何测试当前页面是否有表格和那些 img 元素?
我尝试过:
if ($("#gallery-table img"))
{
alert("Gallery page");
}
但是即使元素不存在,该代码也会在每个页面上运行。
I have a gallery page with a table that has an id. Each table cell has an img element. How do I test if the current page has a table and those img elements?
I tried:
if ($("#gallery-table img"))
{
alert("Gallery page");
}
but that code runs on every page even if the elements do not exist.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试jQuery 都会返回一个对象,因此您需要查看该对象中是否存在任何内容。
无论如何,
Try
jQuery is returning an object no matter what, so you'll need to see if anything exists in that object.