jQuery检查imgsrc给出未定义的
我试图检查特定的jQuery检查imgsrc给出未定义的,jquery,Jquery,我试图检查特定的元素是否有特定的链接。所以我要这样做: 但是,它不起作用。它永远找不到它,而else只是提醒我未定义。你知道为什么吗 这是wordpress中的钩子上的钩子,但通常的jquery是有效的(以防有人想知道我为什么要尝试查找自己的链接)。元素似乎还没有加载 if($('.watchface').find('img').attr("src") == 'http://somelink.com/that/im/trying/to/find.png') {
元素是否有特定的链接。所以我要这样做:
但是,它不起作用。它永远找不到它,而else
只是提醒我未定义。你知道为什么吗
这是wordpress中的钩子上的钩子,但通常的jquery是有效的(以防有人想知道我为什么要尝试查找自己的链接)。元素似乎还没有加载
if($('.watchface').find('img').attr("src") == 'http://somelink.com/that/im/trying/to/find.png')
{
alert("Link found");
}
else
{
alert($('.watchface').find('img').attr("src"));
}
img元素是否具有WatchFace类它是img元素的持有者。这里的HTML:这显示了什么<代码>控制台.log($('.watchface');log($('.watchface').find('img'));console.log($('.watchface').find('img').attr('src'))它的工作部件在
.watchface
元件内是否有多个img
?因为如果是这种情况,find('img')
将返回jQuery集合。
$(document).ready(
if($('.watchface').find('img').attr("src") == 'http://somelink.com/that/im/trying/to/find.png')
{
alert("Link found");
}
else
{
alert($('.watchface').find('img').attr("src"));
});